From d303fcc621551b1aa4653995632eec5cc04564be Mon Sep 17 00:00:00 2001 From: dhh Date: Sat, 16 Sep 2023 09:58:09 -0700 Subject: [PATCH] Extract Containers and Images concerns --- lib/kamal/commands/app.rb | 38 +--------------------------- lib/kamal/commands/app/containers.rb | 23 +++++++++++++++++ lib/kamal/commands/app/images.rb | 13 ++++++++++ 3 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 lib/kamal/commands/app/containers.rb create mode 100644 lib/kamal/commands/app/images.rb diff --git a/lib/kamal/commands/app.rb b/lib/kamal/commands/app.rb index 23aeb2f6..9cc1bcfa 100644 --- a/lib/kamal/commands/app.rb +++ b/lib/kamal/commands/app.rb @@ -1,5 +1,5 @@ class Kamal::Commands::App < Kamal::Commands::Base - include Assets, Cord, Execution + include Assets, Containers, Cord, Execution, Images ACTIVE_DOCKER_STATUSES = [ :running, :restarting ] @@ -85,42 +85,6 @@ class Kamal::Commands::App < Kamal::Commands::Base end - def list_containers - docker :container, :ls, "--all", *filter_args - end - - def list_container_names - [ *list_containers, "--format", "'{{ .Names }}'" ] - end - - def remove_container(version:) - pipe \ - container_id_for(container_name: container_name(version)), - xargs(docker(:container, :rm)) - end - - def rename_container(version:, new_version:) - docker :rename, container_name(version), container_name(new_version) - end - - def remove_containers - docker :container, :prune, "--force", *filter_args - end - - - def list_images - docker :image, :ls, config.repository - end - - def remove_images - docker :image, :prune, "--all", "--force", *filter_args - end - - def tag_current_image_as_latest - docker :tag, config.absolute_image, config.latest_image - end - - def make_env_directory make_directory role_config.host_env_directory end diff --git a/lib/kamal/commands/app/containers.rb b/lib/kamal/commands/app/containers.rb new file mode 100644 index 00000000..a62d9a35 --- /dev/null +++ b/lib/kamal/commands/app/containers.rb @@ -0,0 +1,23 @@ +module Kamal::Commands::App::Containers + def list_containers + docker :container, :ls, "--all", *filter_args + end + + def list_container_names + [ *list_containers, "--format", "'{{ .Names }}'" ] + end + + def remove_container(version:) + pipe \ + container_id_for(container_name: container_name(version)), + xargs(docker(:container, :rm)) + end + + def rename_container(version:, new_version:) + docker :rename, container_name(version), container_name(new_version) + end + + def remove_containers + docker :container, :prune, "--force", *filter_args + end +end diff --git a/lib/kamal/commands/app/images.rb b/lib/kamal/commands/app/images.rb new file mode 100644 index 00000000..9b1ae0b8 --- /dev/null +++ b/lib/kamal/commands/app/images.rb @@ -0,0 +1,13 @@ +module Kamal::Commands::App::Images + def list_images + docker :image, :ls, config.repository + end + + def remove_images + docker :image, :prune, "--all", "--force", *filter_args + end + + def tag_current_image_as_latest + docker :tag, config.absolute_image, config.latest_image + end +end