Skip to content

Commit

Permalink
Merge pull request #155 from bibendi/feature/compose-down-all
Browse files Browse the repository at this point in the history
Add command to shutdown all running compose projects
  • Loading branch information
bibendi authored Sep 24, 2022
2 parents 5b51422 + c39ca78 commit 5f85567
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ AllCops:
- 'tmp/**/*'
NewCops: enable

RSpec:
Language:
Expectations:
- expected_subprocess
- expected_exec

Style/FrozenStringLiteralComment:
Enabled: true

Expand Down
11 changes: 10 additions & 1 deletion lib/dip/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ def stop(*argv)
end

desc "down [OPTIONS]", "Run `docker-compose down` command"
method_option :help, aliases: "-h", type: :boolean, desc: "Display usage information"
method_option :all, aliases: "-A", type: :boolean, desc: "Shutdown all running docker-compose projects"
def down(*argv)
compose("down", *argv)
if options[:help]
invoke :help, ["down"]
elsif options[:all]
require_relative "commands/down_all"
Dip::Commands::DownAll.new.execute
else
compose("down", *argv)
end
end

desc "run [OPTIONS] CMD [ARGS]", "Run configured command in a docker-compose service. `run` prefix may be omitted"
Expand Down
15 changes: 15 additions & 0 deletions lib/dip/commands/down_all.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require_relative "../command"

module Dip
module Commands
class DownAll < Dip::Command
def execute
exec_subprocess(
"docker rm --volumes $(docker stop $(docker ps --filter 'label=com.docker.compose.project' -q))"
)
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lib/dip/commands/down_all_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "shellwords"
require "dip/cli"
require "dip/commands/down_all"

describe Dip::Commands::DownAll do
let(:cli) { Dip::CLI }

before { cli.start "down -A".shellsplit }

it "runs a valid command" do
expected_subprocess(
"docker rm --volumes $(docker stop $(docker ps --filter 'label=com.docker.compose.project' -q))",
[]
)
end
end

0 comments on commit 5f85567

Please sign in to comment.