Class: Construi::Target
- Inherits:
-
Object
- Object
- Construi::Target
- Defined in:
- lib/construi/target.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #commands ⇒ Object
- #create_initial_image ⇒ Object
-
#initialize(name, config) ⇒ Target
constructor
A new instance of Target.
- #link_option(links) ⇒ Object
- #run ⇒ Object
- #start_linked_images ⇒ Object
- #volumes_from_option(config, links) ⇒ Object
Constructor Details
#initialize(name, config) ⇒ Target
7 8 9 10 |
# File 'lib/construi/target.rb', line 7 def initialize(name, config) @name = name @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/construi/target.rb', line 5 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/construi/target.rb', line 5 def name @name end |
Instance Method Details
#commands ⇒ Object
12 13 14 |
# File 'lib/construi/target.rb', line 12 def commands @config.commands end |
#create_initial_image ⇒ Object
42 43 44 |
# File 'lib/construi/target.rb', line 42 def create_initial_image return Image.from(@config) end |
#link_option(links) ⇒ Object
57 58 59 60 61 |
# File 'lib/construi/target.rb', line 57 def link_option(links) links.each_with_object([]) do |l, o| o << "#{l.id}:#{l.name}" end end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/construi/target.rb', line 16 def run Console.progress "Running #{name}..." links = start_linked_images begin final_image = IntermediateImage.seed(create_initial_image).reduce(commands) do |image, command| Console.progress " > #{command}" = config..merge( links: link_option(links), volumes_from: volumes_from_option(config, links), name: name ) image.run command, end final_image.delete ensure links.map(&:delete) end Console.progress "Build Successful." end |
#start_linked_images ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/construi/target.rb', line 46 def start_linked_images @config.links.map do |(name, config)| = config..merge( name: name, log_lifecycle: true ) Image.from(config).start end end |
#volumes_from_option(config, links) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/construi/target.rb', line 63 def volumes_from_option(config, links) config.volumes_from.each_with_object([]) do |v, o| volume_from = links.detect { |l| l.name == v } o << (volume_from.nil? ? v : volume_from.id) end end |