Class: Conjure::Docker::Template
- Inherits:
-
Object
- Object
- Conjure::Docker::Template
- Defined in:
- lib/conjure/docker/template.rb
Instance Method Summary collapse
- #add_file(filename, remote_name) ⇒ Object
- #add_file_data(data, remote_name) ⇒ Object
- #environment(hash) ⇒ Object
-
#initialize(base_image_name) ⇒ Template
constructor
A new instance of Template.
- #run(command) ⇒ Object
- #source ⇒ Object
- #start(container_host, command, options = {}) ⇒ Object
- #volume(name) ⇒ Object
Constructor Details
#initialize(base_image_name) ⇒ Template
Returns a new instance of Template.
7 8 9 10 |
# File 'lib/conjure/docker/template.rb', line 7 def initialize(base_image_name) @commands = ["FROM #{base_image_name}"] @file_data = {} end |
Instance Method Details
#add_file(filename, remote_name) ⇒ Object
12 13 14 |
# File 'lib/conjure/docker/template.rb', line 12 def add_file(filename, remote_name) add_file_data File.read(filename), remote_name end |
#add_file_data(data, remote_name) ⇒ Object
16 17 18 19 20 |
# File 'lib/conjure/docker/template.rb', line 16 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 |
#environment(hash) ⇒ Object
34 35 36 |
# File 'lib/conjure/docker/template.rb', line 34 def environment(hash) hash.each { |key, value| @commands << "ENV #{key} #{value}" } end |
#run(command) ⇒ Object
22 23 24 |
# File 'lib/conjure/docker/template.rb', line 22 def run(command) @commands << "RUN #{command}" end |
#source ⇒ Object
30 31 32 |
# File 'lib/conjure/docker/template.rb', line 30 def source @commands.join "\n" end |
#start(container_host, command, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/conjure/docker/template.rb', line 38 def start(container_host, command, = {}) if container_names().all? { |name| container_host.running? name } puts "Detected all #{[:name]} containers running." else puts "Building #{[:name]} base image..." image_name = container_host.build(image_source_files) = .merge((container_host, image_name, )) if [:volumes] container_host.start(image_name, command, ) end end |
#volume(name) ⇒ Object
26 27 28 |
# File 'lib/conjure/docker/template.rb', line 26 def volume(name) @commands << "VOLUME #{name}" end |