Sha256: 351bc3ba10334d0f8255a129fee2ce911586a1a6267954bfafb0fbcc6bf1aba8

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'open3'

module Njord
  class DockerHandler
    class << self
      def build_images
        Njord.config.images.each do |image_config|
          execute("docker build -t #{image_config.image_name}:#{image_tag(image_config)}" \
            " -f #{image_config.dockerfile} .")
        end
      end

      def tag_images
        Njord.config.images.each do |image_config|
          execute("docker tag #{image_config.image_name}:#{image_tag(image_config)} #{image_config.docker_repo}/#{image_config.image_name}:#{image_tag(image_config)}")
          execute("docker tag #{image_config.image_name}:#{image_tag(image_config)} #{image_config.docker_repo}/#{image_config.image_name}:latest")
        end
      end

      def push_images
        Njord.config.images.each do |image_config|
          execute("docker push #{image_config.docker_repo}/#{image_config.image_name}:#{image_tag(image_config)}")
          execute("docker push #{image_config.docker_repo}/#{image_config.image_name}:latest")
        end
      end

      private
      def execute(cmd)
        puts "Executing #{cmd}"
        raise RuntimeError unless system(cmd, out: $stdout, err: :out)
      end

      def image_tag(image_config)
        case image_config.tagging
        when :sem_ver then "" # TODO
        else
          image_tag_via_git
        end
      end

      def image_tag_via_git
        `git rev-parse --short HEAD`.strip
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
njord-0.1.2 lib/njord/docker_handler.rb