Skip to content

Commit

Permalink
feat: add ability to override compose command
Browse files Browse the repository at this point in the history
  • Loading branch information
d-lebed committed Mar 18, 2022
1 parent 9eb5faf commit b4eda5a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
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
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

0 comments on commit b4eda5a

Please sign in to comment.