Sha256: c5d121675901528e3defc922487e526851353e648cc09d282afcbc89283cc761

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

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

module RakeDocker
  module Tasks
    class Tag < TaskLib
      parameter :name, :default => :tag

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

      parameter :tags, :required => true

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

      def define
        desc "Tag #{image_name} image for repository"
        task name do
          params = OpenStruct.new(
              image_name: image_name,
              repository_name: repository_name
          )

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

          images = Docker::Image.all(filter: repository_name)
          if images.empty?
            raise RakeDocker::ImageNotFound,
                  "No image found with name: '#{image_name}'"
          end

          image = images.first

          derived_tags.each do |tag|
            image.tag(repo: derived_repository_url,
                      tag: tag,
                      force: true)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rake_docker-0.9.0 lib/rake_docker/tasks/tag.rb
rake_docker-0.8.0 lib/rake_docker/tasks/tag.rb
rake_docker-0.7.4 lib/rake_docker/tasks/tag.rb
rake_docker-0.7.3 lib/rake_docker/tasks/tag.rb
rake_docker-0.7.2 lib/rake_docker/tasks/tag.rb
rake_docker-0.7.1 lib/rake_docker/tasks/tag.rb
rake_docker-0.7.0 lib/rake_docker/tasks/tag.rb