Sha256: 4ed479fd1d2340468fbb838d6747698f37733509631ad08c897b801fc8e8a25e

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 KB

Contents

require 'docker'
require 'ostruct'
require_relative '../tasklib'

module RakeDocker
  module Tasks
    class Push < TaskLib
      parameter :name, :default => :push
      parameter :argument_names, :default => []

      parameter :image_name, :required => true
      parameter :repository_url, :required => true

      parameter :credentials
      parameter :tags, :required => true

      def process_arguments(args)
        self.name = args[0] if args[0]
      end

      def define
        desc "Push #{image_name} image to repository"
        task name, argument_names do |_, args|
          params = OpenStruct.new(
              image_name: image_name,
              repository_url: repository_url,
              credentials: credentials,
              tag: tags
          )

          derived_repository_url = repository_url.respond_to?(:call) ?
              repository_url.call(*[args, params].slice(0, repository_url.arity)) :
              repository_url
          derived_credentials = credentials.respond_to?(:call) ?
              credentials.call(*[args, params].slice(0, credentials.arity)) :
              credentials
          derived_tags = tags.respond_to?(:call) ?
              tags.call(*[args, params].slice(0, tags.arity)) :
              tags

          Docker.authenticate!(derived_credentials) if derived_credentials

          images = Docker::Image.all(filter: derived_repository_url)
          if images.empty?
            raise RakeDocker::ImageNotFound,
                  "No image found for repository: '#{derived_repository_url}'"
          end

          image = images.first
          derived_tags.each do |tag|
            image.push(nil, tag: tag) do |chunk|
              DockerOutput.print chunk
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rake_docker-0.23.0 lib/rake_docker/tasks/push.rb
rake_docker-0.22.0.pre.pre.1 lib/rake_docker/tasks/push.rb
rake_docker-0.21.0 lib/rake_docker/tasks/push.rb
rake_docker-0.20.0.pre.pre.4 lib/rake_docker/tasks/push.rb
rake_docker-0.20.0.pre.pre.3 lib/rake_docker/tasks/push.rb
rake_docker-0.20.0.pre.pre.2 lib/rake_docker/tasks/push.rb
rake_docker-0.20.0.pre.pre.1 lib/rake_docker/tasks/push.rb
rake_docker-0.19.0 lib/rake_docker/tasks/push.rb
rake_docker-0.18.0.pre.pre.1 lib/rake_docker/tasks/push.rb
rake_docker-0.17.0 lib/rake_docker/tasks/push.rb
rake_docker-0.16.1.pre2 lib/rake_docker/tasks/push.rb
rake_docker-0.16.1.pre1 lib/rake_docker/tasks/push.rb