Class: Construi::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/construi/target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/construi/target.rb', line 5

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/construi/target.rb', line 5

def name
  @name
end

Instance Method Details

#commandsObject



12
13
14
# File 'lib/construi/target.rb', line 12

def commands
  @config.commands
end

#create_initial_imageObject



42
43
44
# File 'lib/construi/target.rb', line 42

def create_initial_image
  return Image.from(@config)
end


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

#runObject



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}"

      options = config.options.merge(
        links: link_option(links),
        volumes_from: volumes_from_option(config, links),
        name: name
      )

      image.run command, options
    end

    final_image.delete
  ensure
    links.map(&:delete)
  end

  Console.progress "Build Successful."
end

#start_linked_imagesObject



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)|
    options = config.options.merge(
      name: name,
      log_lifecycle: true
    )

    Image.from(config).start options
  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