By default we keep 5 containers around for rollback. The containers don't take much space, but the images for them can. Make the number of containers to retain configurable, either in the config with the `retain_containers` setting on the command line with the `--retain` option.
36 lines
1020 B
Ruby
36 lines
1020 B
Ruby
class Kamal::Cli::Prune < Kamal::Cli::Base
|
|
desc "all", "Prune unused images and stopped containers"
|
|
def all
|
|
mutating do
|
|
containers
|
|
images
|
|
end
|
|
end
|
|
|
|
desc "images", "Prune unused images"
|
|
def images
|
|
mutating do
|
|
on(KAMAL.hosts) do
|
|
execute *KAMAL.auditor.record("Pruned images"), verbosity: :debug
|
|
execute *KAMAL.prune.dangling_images
|
|
execute *KAMAL.prune.tagged_images
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "containers", "Prune all stopped containers, except the last n (default 5)"
|
|
option :retain, type: :numeric, default: nil, desc: "Number of containers to retain"
|
|
def containers
|
|
retain = options.fetch(:retain, KAMAL.config.retain_containers)
|
|
raise "retain must be at least 1" if retain < 1
|
|
|
|
mutating do
|
|
on(KAMAL.hosts) do
|
|
execute *KAMAL.auditor.record("Pruned containers"), verbosity: :debug
|
|
execute *KAMAL.prune.app_containers(retain: retain)
|
|
execute *KAMAL.prune.healthcheck_containers
|
|
end
|
|
end
|
|
end
|
|
end
|