Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ def start
end

desc "stop", "Stop app container on servers"
option :container_id, desc: "Docker container ID to stop (instead of stopping all containers)"
def stop
container_id = options[:container_id]

with_lock do
on(KAMAL.app_hosts) do |host|
roles = KAMAL.roles_on(host)

roles.each do |role|
app = KAMAL.app(role: role, host: host)
app = KAMAL.app(role: role, host: host, container_id: container_id)
execute *KAMAL.auditor.record("Stopped app", role: role), verbosity: :debug

if role.running_proxy?
Expand Down
4 changes: 2 additions & 2 deletions lib/kamal/commander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def accessory_names
config.accessories&.collect(&:name) || []
end

def app(role: nil, host: nil)
Kamal::Commands::App.new(config, role: role, host: host)
def app(role: nil, host: nil, container_id: nil)
Kamal::Commands::App.new(config, role: role, host: host, container_id: container_id)
end

def accessory(name)
Expand Down
7 changes: 4 additions & 3 deletions lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ class Kamal::Commands::App < Kamal::Commands::Base

ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]

attr_reader :role, :host
attr_reader :role, :host, :container_id

delegate :container_name, to: :role

def initialize(config, role: nil, host: nil)
def initialize(config, role: nil, host: nil, container_id: nil)
super(config)
@role = role
@host = host
@container_id = container_id
end

def run(hostname: nil)
Expand Down Expand Up @@ -54,7 +55,7 @@ def info


def current_running_container_id
current_running_container(format: "--quiet")
container_id || current_running_container(format: "--quiet")
end

def container_id_for_version(version, only_running: false)
Expand Down
6 changes: 6 additions & 0 deletions test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ class CliAppTest < CliTestCase
end
end

test "stop with container id" do
run_command("stop", "--container-id", "abcd1234").tap do |output|
assert_match "abcd1234 | xargs docker stop", output
end
end

test "stale_containers" do
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=destination=", "--filter", "label=role=web", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
Expand Down
Loading