Split out proper Prune command
This commit is contained in:
@@ -21,5 +21,6 @@ module Mrsk::Commands
|
||||
end
|
||||
|
||||
require "mrsk/commands/app"
|
||||
require "mrsk/commands/prune"
|
||||
require "mrsk/commands/traefik"
|
||||
require "mrsk/commands/registry"
|
||||
|
||||
13
lib/mrsk/commands/prune.rb
Normal file
13
lib/mrsk/commands/prune.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Mrsk::Commands::Prune < Mrsk::Commands::Base
|
||||
PRUNE_IMAGES_AFTER = 30.days.in_hours.to_i
|
||||
PRUNE_CONTAINERS_AFTER = 3.days.in_hours.to_i
|
||||
|
||||
def images
|
||||
docker :image, :prune, "-f", "--filter", "until=#{PRUNE_IMAGES_AFTER}h"
|
||||
end
|
||||
|
||||
def containers
|
||||
docker :image, :prune, "-f", "--filter", "until=#{PRUNE_IMAGES_AFTER}h"
|
||||
docker :container, :prune, "-f", "--filter", "label=service=#{config.service}", "--filter", "'until=#{PRUNE_CONTAINERS_AFTER}h'"
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,6 @@
|
||||
require_relative "setup"
|
||||
|
||||
PRUNE_IMAGES_AFTER = 30.days.in_hours.to_i
|
||||
PRUNE_CONTAINERS_AFTER = 3.days.in_hours.to_i
|
||||
prune = Mrsk::Commands::Prune.new(MRSK_CONFIG)
|
||||
|
||||
namespace :mrsk do
|
||||
desc "Prune unused images and stopped containers"
|
||||
@@ -10,12 +9,12 @@ namespace :mrsk do
|
||||
namespace :prune do
|
||||
desc "Prune unused images older than 30 days"
|
||||
task :images do
|
||||
on(MRSK_CONFIG.hosts) { execute "docker image prune -f --filter 'until=#{PRUNE_IMAGES_AFTER}h'" }
|
||||
on(MRSK_CONFIG.hosts) { execute *prune.images }
|
||||
end
|
||||
|
||||
desc "Prune stopped containers for the service older than 3 days"
|
||||
task :containers do
|
||||
on(MRSK_CONFIG.hosts) { execute "docker container prune -f --filter label=service=#{MRSK_CONFIG.service} --filter 'until=#{PRUNE_CONTAINERS_AFTER}h'" }
|
||||
on(MRSK_CONFIG.hosts) { execute *prune.containers }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user