Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to override compose command #145

Merged
merged 1 commit into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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