Class: Conjure::Provision::Docker::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/conjure/provision/docker/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_image_name) ⇒ Template

Returns a new instance of Template.



9
10
11
12
# File 'lib/conjure/provision/docker/template.rb', line 9

def initialize(base_image_name)
  @commands = ["FROM #{base_image_name}"]
  @file_data = {}
end

Instance Method Details

#add_file(filename, remote_name) ⇒ Object



14
15
16
# File 'lib/conjure/provision/docker/template.rb', line 14

def add_file(filename, remote_name)
  add_file_data File.read(filename), remote_name
end

#add_file_data(data, remote_name) ⇒ Object



18
19
20
21
22
# File 'lib/conjure/provision/docker/template.rb', line 18

def add_file_data(data, remote_name)
  local_name = "file#{@file_data.length+1}"
  @file_data[local_name] = data
  @commands << "ADD #{local_name} #{remote_name}"
end

#build(platform) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/conjure/provision/docker/template.rb', line 41

def build(platform)
  docker_host = Host.new(platform)
  image_name = prepare_build_directory do |dir|
    docker_host.built_image_name dir
  end
  Image.new docker_host, image_name
end

#prepare_build_directory(&block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/conjure/provision/docker/template.rb', line 32

def prepare_build_directory(&block)
  Dir.mktmpdir do |dir|
    @file_data.merge("Dockerfile" => source).each do |filename, data|
      File.write "#{dir}/#{filename}", data
    end
    yield dir
  end
end

#run(command) ⇒ Object



24
25
26
# File 'lib/conjure/provision/docker/template.rb', line 24

def run(command)
  @commands << "RUN #{command}"
end

#sourceObject



28
29
30
# File 'lib/conjure/provision/docker/template.rb', line 28

def source
  @commands.join "\n"
end