Sha256: 512e58c474121734cb763fbb102cbfdf95e12f664b8d560314cd05838bd16fbe

Contents?: true

Size: 998 Bytes

Versions: 2

Compression:

Stored size: 998 Bytes

Contents

module Kontena::Cli::Apps
  module DockerHelper

    def process_docker_images(services, force_build = false)
      services.each do |name, service|
        if service['build'] && (!image_exist?(service['image']) || force_build)
          abort("'#{service['image']}' is not valid Docker image name") unless validate_image_name(service['image'])
          puts "Building image #{service['image'].colorize(:cyan)}"
          build_docker_image(service['image'], service['build'])

          puts "Pushing image #{service['image'].colorize(:cyan)} to registry"
          push_docker_image(service['image'])
        end
      end
    end

    def validate_image_name(name)
      !(/^[\w.\/\-]+:?+[\w+.]+$/ =~ name).nil?
    end


    def build_docker_image(name, path)
      system("docker build -t #{name} #{path}")
    end

    def push_docker_image(image)
      system("docker push #{image}")
    end

    def image_exist?(image)
      `docker history #{image} 2>&1` ; $?.success?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kontena-cli-0.9.1 lib/kontena/cli/apps/docker_helper.rb
kontena-cli-0.9.0 lib/kontena/cli/apps/docker_helper.rb