class DkComposer::Image
Attributes
actions[RW]
from[RW]
name[RW]
repos[RW]
tag[RW]
Public Class Methods
create(name, *params, **opts, &block)
click to toggle source
# File lib/dkcomposer/image.rb, line 105 def self.create(name, *params, **opts, &block) if name.is_a?(String) opts[:repos] ||= [] opts[:repos].unshift(name) end ret = Image.new(name) ret.config(opts) ret.instance_exec(*params, &block) if block ret end
new(name)
click to toggle source
# File lib/dkcomposer/image.rb, line 6 def initialize(name) @name = name @actions = [] @repos = [] @tag = 'latest' end
Public Instance Methods
build(path = build_path)
click to toggle source
# File lib/dkcomposer/image.rb, line 72 def build(path = build_path) dockerfile = tempfile(to_docker_file, 'Dockerfile', path) build_cmd = [ "pushd #{path}", "docker build -f #{dockerfile} #{repos.map { |repo| '-t ' + repo }.join(' ')} .", 'popd' ].join('&&') run_command(build_cmd) end
full_name()
click to toggle source
# File lib/dkcomposer/image.rb, line 101 def full_name "#{@name}:#{tag}" end
pull()
click to toggle source
# File lib/dkcomposer/image.rb, line 58 def pull repos.each do |repo| pull_cmd = "docker pull #{repo}" run_command(pull_cmd) end end
push()
click to toggle source
# File lib/dkcomposer/image.rb, line 65 def push repos.each do |repo| push_cmd = "docker push #{repo}" run_command(push_cmd) end end
repo()
click to toggle source
# File lib/dkcomposer/image.rb, line 23 def repo repos.first end
to_docker_file()
click to toggle source
# File lib/dkcomposer/image.rb, line 82 def to_docker_file return '' if actions.empty? && @from.nil? actions.clone.unshift([:from, @from]).map do |instruct, *params| "#{instruct.to_s.upcase} #{params.join(' ')}" end.join("\n") end
to_s()
click to toggle source
# File lib/dkcomposer/image.rb, line 89 def to_s ret = <<-DUMP image(:#{@name}) do from "#{@from}" repos #{@repos.map { |r| "'#{r}'" }.join(',')} tag :#{@tag} #{actions.map(&:flatten).map { |a| a.join(' ') }.join("\n")} end DUMP ret end
Also aliased as: dump
use(*params)
click to toggle source
# File lib/dkcomposer/image.rb, line 45 def use(*params) return @use if params.empty? @use = params params.each do |image_name| puts "WARNING: There is no image definition named: :#{image_name}! Pls require the def file " unless IMAGE.key?(image_name) @actions << ['', "#>>>>>>>>>>>>>#{image_name} begin<<<<<<<<<<<<<<<<<<<"] @actions.concat IMAGE[image_name].actions @actions << ['', "#>>>>>>>>>>>>>#{image_name} end<<<<<<<<<<<<<<<<<<<<<"] @actions << ['', ' '] end end