From 5e4d0efc42626d3d364b3ec172ff0df668c46b44 Mon Sep 17 00:00:00 2001 From: Dmitry Lebed <209805+d-lebed@users.noreply.github.com> Date: Fri, 18 Mar 2022 14:02:34 +0400 Subject: [PATCH] feat: add ability to override compose command --- README.md | 10 ++++++ lib/dip/commands/compose.rb | 9 +++++- spec/lib/dip/commands/compose_spec.rb | 45 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1172c84..d9e5e45 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/dip/commands/compose.rb b/lib/dip/commands/compose.rb index 50afbb6..433759c 100644 --- a/lib/dip/commands/compose.rb +++ b/lib/dip/commands/compose.rb @@ -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) @@ -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 diff --git a/spec/lib/dip/commands/compose_spec.rb b/spec/lib/dip/commands/compose_spec.rb index 7d5c7ed..f61d3c4 100644 --- a/spec/lib/dip/commands/compose_spec.rb +++ b/spec/lib/dip/commands/compose_spec.rb @@ -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