Sha256: 41c227598788cf5aec17addfc75566c476d228ab432be57bbd8a3bb901dd0388

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

module Percheron
  module Actions
    class Purge

      include Base

      def initialize(container, force: false)
        @container = container
        @force = force
      end

      def execute!
        results = []
        results << stop!
        results << delete_container!
        results << delete_image!
        results.compact.empty? ? nil : container
      end

      private

        attr_reader :container, :force

        def stop!
          Stop.new(container).execute!
        end

        def delete_image?
          container.image_exists? && container.buildable?
        end

        def delete_container!
          return nil unless container.exists?
          $logger.info "Deleting '#{container.name}' container"
          container.docker_container.remove(force: force)
        rescue Docker::Error::ConflictError => e
          $logger.error "Unable to delete '%s' container - %s" % [ container.name, e.inspect ]
        end

        def delete_image!
          return nil unless delete_image?
          $logger.info "Deleting '#{container.image_name}' image"
          container.image.remove(force: force)
        rescue Docker::Error::ConflictError => e
          $logger.error "Unable to delete '%s' image - %s" % [ container.image_name, e.inspect ]
        end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
percheron-0.7.6 lib/percheron/actions/purge.rb
percheron-0.7.5 lib/percheron/actions/purge.rb
percheron-0.7.4 lib/percheron/actions/purge.rb
percheron-0.7.3 lib/percheron/actions/purge.rb