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

Filter correctly for empty destinations #1193

Merged
merged 1 commit into from
Nov 4, 2024
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
22 changes: 15 additions & 7 deletions lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def stop(version: nil)
end

def info
docker :ps, *filter_args
docker :ps, *container_filter_args
end


Expand All @@ -67,7 +67,7 @@ def current_running_version

def list_versions(*docker_args, statuses: nil)
pipe \
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
docker(:ps, *container_filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
extract_version_from_name
end

Expand All @@ -91,25 +91,33 @@ def latest_image_container(format:)
end

def latest_container(format:, filters: nil)
docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES), argumentize("--filter", filters)
docker :ps, "--latest", *format, *container_filter_args(statuses: ACTIVE_DOCKER_STATUSES), argumentize("--filter", filters)
end

def filter_args(statuses: nil)
argumentize "--filter", filters(statuses: statuses)
def container_filter_args(statuses: nil)
argumentize "--filter", container_filters(statuses: statuses)
end

def image_filter_args
argumentize "--filter", image_filters
end

def extract_version_from_name
# Extract SHA from "service-role-dest-SHA"
%(while read line; do echo ${line##{role.container_prefix}-}; done)
end

def filters(statuses: nil)
def container_filters(statuses: nil)
[ "label=service=#{config.service}" ].tap do |filters|
filters << "label=destination=#{config.destination}" if config.destination
filters << "label=destination=#{config.destination}"
filters << "label=role=#{role}" if role
statuses&.each do |status|
filters << "status=#{status}"
end
end
end

def image_filters
[ "label=service=#{config.service}" ]
end
end
4 changes: 2 additions & 2 deletions lib/kamal/commands/app/containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Kamal::Commands::App::Containers
DOCKER_HEALTH_LOG_FORMAT = "'{{json .State.Health}}'"

def list_containers
docker :container, :ls, "--all", *filter_args
docker :container, :ls, "--all", *container_filter_args
end

def list_container_names
Expand All @@ -20,7 +20,7 @@ def rename_container(version:, new_version:)
end

def remove_containers
docker :container, :prune, "--force", *filter_args
docker :container, :prune, "--force", *container_filter_args
end

def container_health_log(version:)
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/commands/app/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def list_images
end

def remove_images
docker :image, :prune, "--all", "--force", *filter_args
docker :image, :prune, "--all", "--force", *image_filter_args
end

def tag_latest_image
Expand Down
Loading