Skip to content

Commit

Permalink
Merge branch 'master' into change_nginx_proxy_default_image
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi authored Mar 19, 2022
2 parents 3e8220a + d012f75 commit 5767465
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 38 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ Use options `-p, --publish=[]` if you need to additionally publish a container's
dip run -p 3000:3000 bundle exec rackup config.ru
```

You can also override docker compose command by passing `DIP_COMPOSE_COMMAND` if you wish. For example if you want to use [`mutagen-compose`](https://mutagen.io/documentation/orchestration/compose) run `DIP_COMPOSE_COMMAND=mutagen-compose dip run`.

If you want to persist that change you can specify command in `compose` section of dip.yml :

```yml
compose:
command: mutagen-compose
```

### dip ls

List all available run commands.
Expand Down
4 changes: 2 additions & 2 deletions lib/dip/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def down(*argv)

desc "run [OPTIONS] CMD [ARGS]", "Run configured command in a docker-compose service. `run` prefix may be omitted"
method_option :publish, aliases: "-p", type: :string, repeatable: true,
desc: "Publish a container's port(s) to the host"
desc: "Publish a container's port(s) to the host"
method_option :help, aliases: "-h", type: :boolean, desc: "Display usage information"
def run(*argv)
if argv.empty? || options[:help]
Expand All @@ -88,7 +88,7 @@ def run(*argv)

desc "provision", "Execute commands within provision section"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def provision
if options[:help]
invoke :help, ["provision"]
Expand Down
4 changes: 2 additions & 2 deletions lib/dip/cli/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CLI
class Console < Base
desc "start", "Integrate Dip into current shell"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def start
if options[:help]
invoke :help, ["start"]
Expand All @@ -22,7 +22,7 @@ def start

desc "inject", "Inject aliases"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def inject
if options[:help]
invoke :help, ["inject"]
Expand Down
26 changes: 13 additions & 13 deletions lib/dip/cli/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class CLI
class DNS < Base
desc "up", "Run dnsdock container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :name, aliases: "-n", type: :string, default: "dnsdock",
desc: "Container name"
desc: "Container name"
method_option :socket, aliases: "-s", type: :string, default: "/var/run/docker.sock",
desc: "Path to docker socket"
desc: "Path to docker socket"
method_option :net, aliases: "-t", type: :string, default: "frontend",
desc: "Container network name"
desc: "Container network name"
method_option :publish, aliases: "-p", type: :string, default: "53/udp",
desc: "Container port"
desc: "Container port"
method_option :image, aliases: "-i", type: :string, default: "aacebedo/dnsdock:latest-amd64",
desc: "Docker image name"
desc: "Docker image name"
method_option :domain, aliases: "-d", type: :string, default: "docker",
desc: "Top level domain"
desc: "Top level domain"
def up
if options[:help]
invoke :help, ["up"]
Expand All @@ -40,9 +40,9 @@ def up

desc "down", "Stop dnsdock container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :name, aliases: "-n", type: :string, default: "dnsdock",
desc: "Container name"
desc: "Container name"
def down
if options[:help]
invoke :help, ["down"]
Expand All @@ -55,7 +55,7 @@ def down

desc "restart", "Stop and start dnsdock container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def restart(*args)
if options[:help]
invoke :help, ["restart"]
Expand All @@ -68,11 +68,11 @@ def restart(*args)

desc "ip", "Get ip address of dnsdock container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :name, aliases: "-n", type: :string, default: "dnsdock",
desc: "Container name"
desc: "Container name"
method_option :net, aliases: "-t", type: :string, default: "frontend",
desc: "Container network name"
desc: "Container network name"
def ip
if options[:help]
invoke :help, ["status"]
Expand Down
20 changes: 10 additions & 10 deletions lib/dip/cli/nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class CLI
class Nginx < Base
desc "up", "Run nginx container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :name, aliases: "-n", type: :string, default: "nginx",
desc: "Container name"
desc: "Container name"
method_option :socket, aliases: "-s", type: :string, default: "/var/run/docker.sock",
desc: "Path to docker socket"
desc: "Path to docker socket"
method_option :net, aliases: "-t", type: :string, default: "frontend",
desc: "Container network name"
desc: "Container network name"
method_option :publish, aliases: "-p", type: :array, default: ["80:80"],
desc: "Container port(s). For more than one port, separate them by a space"
desc: "Container port(s). For more than one port, separate them by a space"
method_option :image, aliases: "-i", type: :string, default: "nginxproxy/nginx-proxy:latest",
desc: "Docker image name"
desc: "Docker image name"
method_option :domain, aliases: "-d", type: :string, default: "docker",
desc: "Top level domain"
desc: "Top level domain"
method_option :certs, aliases: "-c", type: :string, desc: "Path to ssl certificates"
def up
if options[:help]
Expand All @@ -42,9 +42,9 @@ def up

desc "down", "Stop nginx container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :name, aliases: "-n", type: :string, default: "nginx",
desc: "Container name"
desc: "Container name"
def down
if options[:help]
invoke :help, ["down"]
Expand All @@ -57,7 +57,7 @@ def down

desc "restart", "Stop and start nginx container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def restart(*args)
if options[:help]
invoke :help, ["restart"]
Expand Down
18 changes: 9 additions & 9 deletions lib/dip/cli/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class CLI
class SSH < Base
desc "up", "Run ssh-agent container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
method_option :key, aliases: "-k", type: :string, default: "$HOME/.ssh/id_rsa",
desc: "Path to ssh key"
desc: "Path to ssh key"
method_option :volume, aliases: "-v", type: :string, default: "$HOME",
desc: "Mounted docker volume"
desc: "Mounted docker volume"
method_option :interactive, aliases: "-t", type: :boolean, default: true,
desc: "Run in interactive mode"
desc: "Run in interactive mode"
method_option :user, aliases: "-u", type: :string,
desc: "UID for ssh-agent container"
desc: "UID for ssh-agent container"
# Backward compatibility
method_option :nonteractive, aliases: "-T", type: :boolean,
desc: "Run in noninteractive mode"
desc: "Run in noninteractive mode"
def up
if options[:help]
invoke :help, ["up"]
Expand All @@ -38,7 +38,7 @@ def up

desc "down", "Stop ssh-agent container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def down
if options[:help]
invoke :help, ["down"]
Expand All @@ -49,7 +49,7 @@ def down

desc "restart", "Stop and start ssh-agent container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def restart(*args)
if options[:help]
invoke :help, ["restart"]
Expand All @@ -62,7 +62,7 @@ def restart(*args)

desc "status", "Show status of ssh-agent container"
method_option :help, aliases: "-h", type: :boolean,
desc: "Display usage information"
desc: "Display usage information"
def status
if options[:help]
invoke :help, ["status"]
Expand Down
9 changes: 8 additions & 1 deletion lib/dip/commands/compose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def execute

compose_argv = Array(find_files) + Array(cli_options) + argv

if compose_v2?
if (override_command = compose_command_override)
override_command, *override_args = override_command.split(" ")
exec_program(override_command, override_args.concat(compose_argv), shell: shell)
elsif compose_v2?
exec_program("docker", compose_argv.unshift("compose"), shell: shell)
else
exec_program("docker-compose", compose_argv, shell: shell)
Expand Down Expand Up @@ -80,6 +83,10 @@ def compose_v2?

!!exec_subprocess("docker", "compose version", panic: false, out: File::NULL, err: File::NULL)
end

def compose_command_override
Dip.env["DIP_COMPOSE_COMMAND"] || config[:command]
end
end
end
end
45 changes: 45 additions & 0 deletions spec/lib/dip/commands/compose_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,49 @@
it { expected_exec("docker-compose", ["--file", file, "run"]) }
end
end

context "when compose command specified in config", config: true do
context "when compose command contains spaces" do
let(:config) { {compose: {command: "foo compose"}} }

before { cli.start "compose run".shellsplit }

it { expected_exec("foo compose", "run") }
end

context "when compose command does not contain spaces" do
let(:config) { {compose: {command: "foo-compose"}} }

before { cli.start "compose run".shellsplit }

it { expected_exec("foo-compose", "run") }
end
end

context "when DIP_COMPOSE_COMMAND is specified in environment", env: true do
context "when DIP_COMPOSE_COMMAND contains spaces" do
let(:env) { {"DIP_COMPOSE_COMMAND" => "foo compose"} }

before { cli.start "compose run".shellsplit }

it { expected_exec("foo compose", "run") }
end

context "when DIP_COMPOSE_COMMAND does not contain spaces" do
let(:env) { {"DIP_COMPOSE_COMMAND" => "foo-compose"} }

before { cli.start "compose run".shellsplit }

it { expected_exec("foo-compose", "run") }
end

context "when compose command specified in config", config: true do
let(:config) { {compose: {command: "foo compose"}} }
let(:env) { {"DIP_COMPOSE_COMMAND" => "bar-compose"} }

before { cli.start "compose run".shellsplit }

it { expected_exec("bar-compose", "run") }
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/dip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Dip do
it "has a version number" do
expect(Dip::VERSION).not_to be nil
expect(Dip::VERSION).not_to be_nil
end

describe ".config" do
Expand Down

0 comments on commit 5767465

Please sign in to comment.