Use image tag to determine stale containers
Use current_running_version to determine the latest version when finding stale containers.
This commit is contained in:
@@ -136,7 +136,10 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
||||
roles = KAMAL.roles_on(host)
|
||||
|
||||
roles.each do |role|
|
||||
cli.send(:stale_versions, host: host, role: role).each do |version|
|
||||
versions = capture_with_info(*KAMAL.app(role: role).list_versions, raise_on_non_zero_exit: false).split("\n")
|
||||
versions -= [ capture_with_info(*KAMAL.app(role: role).current_running_version, raise_on_non_zero_exit: false).strip ]
|
||||
|
||||
versions.each do |version|
|
||||
if stop
|
||||
puts_by_host host, "Stopping stale container for role #{role} with version #{version}"
|
||||
execute *KAMAL.app(role: role).stop(version: version), raise_on_non_zero_exit: false
|
||||
@@ -272,17 +275,6 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
||||
version.presence
|
||||
end
|
||||
|
||||
def stale_versions(host:, role:)
|
||||
versions = nil
|
||||
on(host) do
|
||||
versions = \
|
||||
capture_with_info(*KAMAL.app(role: role).list_versions, raise_on_non_zero_exit: false)
|
||||
.split("\n")
|
||||
.drop(1)
|
||||
end
|
||||
versions
|
||||
end
|
||||
|
||||
def version_or_latest
|
||||
options[:version] || KAMAL.config.latest_tag
|
||||
end
|
||||
|
||||
@@ -49,9 +49,7 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
||||
|
||||
|
||||
def current_running_container_id
|
||||
pipe \
|
||||
shell(chain(latest_image_container_id, latest_container_id)),
|
||||
[ :head, "-1" ]
|
||||
current_running_container(format: "--quiet")
|
||||
end
|
||||
|
||||
def container_id_for_version(version, only_running: false)
|
||||
@@ -60,8 +58,7 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
||||
|
||||
def current_running_version
|
||||
pipe \
|
||||
shell(chain(latest_image_container_name, latest_container_name)),
|
||||
[ :head, "-1" ],
|
||||
current_running_container(format: "--format '{{.Names}}'"),
|
||||
extract_version_from_name
|
||||
end
|
||||
|
||||
@@ -90,28 +87,18 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
||||
docker :image, :ls, *argumentize("--filter", "reference=#{config.latest_image}"), "--format", "'{{.ID}}'"
|
||||
end
|
||||
|
||||
def latest_image_container_id
|
||||
latest_image_container format: "--quiet"
|
||||
def current_running_container(format:)
|
||||
pipe \
|
||||
shell(chain(latest_image_container(format: format), latest_container(format: format))),
|
||||
[ :head, "-1" ]
|
||||
end
|
||||
|
||||
def latest_container_id
|
||||
latest_container format: "--quiet"
|
||||
def latest_image_container(format:)
|
||||
latest_container format: format, filters: [ "ancestor=$(#{latest_image_id.join(" ")})" ]
|
||||
end
|
||||
|
||||
def latest_image_container_name
|
||||
latest_image_container format: "--format '{{.Names}}'"
|
||||
end
|
||||
|
||||
def latest_container_name
|
||||
latest_container format: "--format '{{.Names}}'"
|
||||
end
|
||||
|
||||
def latest_image_container(format: nil)
|
||||
docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES), "--filter", "ancestor=$(#{latest_image_id.join(" ")})"
|
||||
end
|
||||
|
||||
def latest_container(format:)
|
||||
docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES)
|
||||
def latest_container(format:, filters: nil)
|
||||
docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES), argumentize("--filter", filters)
|
||||
end
|
||||
|
||||
def filter_args(statuses: nil)
|
||||
|
||||
Reference in New Issue
Block a user