Class: Nvoi::Cli::Deploy::Steps::CleanupImages
- Inherits:
-
Object
- Object
- Nvoi::Cli::Deploy::Steps::CleanupImages
- Defined in:
- lib/nvoi/cli/deploy/steps/cleanup_images.rb
Overview
CleanupImages handles cleanup of old container images
Instance Method Summary collapse
-
#initialize(config, ssh, log) ⇒ CleanupImages
constructor
A new instance of CleanupImages.
- #run(current_tag) ⇒ Object
Constructor Details
#initialize(config, ssh, log) ⇒ CleanupImages
Returns a new instance of CleanupImages.
9 10 11 12 13 |
# File 'lib/nvoi/cli/deploy/steps/cleanup_images.rb', line 9 def initialize(config, ssh, log) @config = config @ssh = ssh @log = log end |
Instance Method Details
#run(current_tag) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nvoi/cli/deploy/steps/cleanup_images.rb', line 15 def run(current_tag) keep_count = @config.keep_count_value prefix = @config.container_prefix @log.info "Cleaning up old images (keeping %d)", keep_count containerd = External::Containerd.new(@ssh) # List all images = containerd.list_images("#{prefix}:*") # Sort by tag (timestamp), keep newest = .sort.reverse = .take(keep_count) # Make sure current tag is kept << current_tag unless .include?(current_tag) << "latest" containerd.cleanup_old_images(prefix, .uniq) @log.success "Old images cleaned up" end |