Class: Conjure::Provision::Docker::Template
- Inherits:
-
Object
- Object
- Conjure::Provision::Docker::Template
- Defined in:
- lib/conjure/provision/docker/template.rb
Instance Method Summary collapse
- #add_file(filename, remote_name) ⇒ Object
- #add_file_data(data, remote_name) ⇒ Object
- #build(platform) ⇒ Object
-
#initialize(base_image_name) ⇒ Template
constructor
A new instance of Template.
- #prepare_build_directory(&block) ⇒ Object
- #run(command) ⇒ Object
- #source ⇒ Object
- #volume(name) ⇒ Object
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
45 46 47 48 49 50 51 |
# File 'lib/conjure/provision/docker/template.rb', line 45 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
36 37 38 39 40 41 42 43 |
# File 'lib/conjure/provision/docker/template.rb', line 36 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 |
#source ⇒ Object
32 33 34 |
# File 'lib/conjure/provision/docker/template.rb', line 32 def source @commands.join "\n" end |
#volume(name) ⇒ Object
28 29 30 |
# File 'lib/conjure/provision/docker/template.rb', line 28 def volume(name) @commands << "VOLUME #{name}" end |