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

Add command to shutdown all running compose projects #155

Merged
merged 1 commit into from
Sep 24, 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
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