Sha256: 047a16d78c30de5b0accd8fdaf19c85aa2efcebd7ba3af58ea9fc98ba719849d

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Percheron
  module Actions
    class Recreate

      include Base

      def initialize(unit, start: false)
        @unit = unit
        @start = start
      end

      def execute!
        results = []
        if recreate?
          results << recreate!
          results << start!
        else
          inform!
        end
        results.compact.empty? ? nil : unit
      end

      private

        attr_reader :unit, :start
        alias_method :start?, :start

        def recreate?
          !unit.versions_match? || !unit.dockerfile_md5s_match?
        end

        def inform!
          return nil unless unit.dockerfile_md5s_match?
          $logger.info "Container '#{unit.name}' - No Dockerfile changes or version bump"
        end

        def recreate!
          $logger.debug "Container '#{unit.name}' exists but will be recreated"
          Purge.new(unit).execute!
          Create.new(unit).execute!
        end

        def start!
          Start.new(unit).execute! if start?
        end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
percheron-0.7.7 lib/percheron/actions/recreate.rb