Sha256: 57cb3b763a6dbd6439b1ef0c2973aa298bbd3883984d0fae470500b756934b1f
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
module Percheron module Actions class Purge include Base def initialize(unit, force: false) @unit = unit @force = force end def execute! results = [] results << stop! results << delete_unit! if delete_unit? results << delete_image! if delete_image? results.compact.empty? ? nil : unit end private attr_reader :unit, :force def stop! Stop.new(unit).execute! end def delete_unit? unit.exists? end def delete_image? unit.image_exists? && unit.buildable? end def opts { force: force } end def delete_unit! delete!('unit', unit.display_name) { unit.container.remove(opts) } end def delete_image! delete!('image', unit.image_name) { unit.image.remove(opts) } end def delete!(type, value) $logger.info("Deleting '%s' %s" % [ value, type ]) yield rescue Docker::Error::ConflictError => e $logger.error("Unable to delete '%s' %s - %s" % [ value, type, e.inspect ]) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
percheron-0.8.1 | lib/percheron/actions/purge.rb |
percheron-0.8.0 | lib/percheron/actions/purge.rb |