Sha256: c8ef2d706a1f7fce266f82f82f3c003a361a198e0c7af6f925f9c2be5673b03c

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

require 'active_support/core_ext/module/delegation'

class Ufo::Docker
  class Pusher
    include Ufo::Util

    delegate :full_image_name, to: :builder
    attr_reader :last_image_name
    def initialize(image, options)
      @options = options
      @last_image_name = image || full_image_name
    end

    def push
      update_auth_token
      start_time = Time.now
      message = "Pushed #{last_image_name} docker image."
      if @options[:noop]
        message = "NOOP #{message}"
      else
        command = "docker push #{last_image_name}"
        puts "=> #{command}".colorize(:green)
        success = execute(command, use_system: true)
        unless success
          puts "ERROR: The docker image fail to push.".colorize(:red)
          exit 1
        end
      end
      took = Time.now - start_time
      message << " Took #{pretty_time(took)}.".green
      puts message unless @options[:mute]
    end

    def builder
      @builder ||= Builder.new(@options.merge(image: last_image_name))
    end

    def update_auth_token
      auth = Ufo::Ecr::Auth.new(last_image_name)
      # wont update auth token unless the image being pushed in the ECR image format
      auth.update if auth.ecr_image?
    end

    # full_image - does not include the tag
    def image_name
      settings["image"]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ufo-3.4.3 lib/ufo/docker/pusher.rb
ufo-3.4.2 lib/ufo/docker/pusher.rb
ufo-3.4.1 lib/ufo/docker/pusher.rb
ufo-3.4.0 lib/ufo/docker/pusher.rb