Class: Buildserver::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/buildserver/role.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role) ⇒ Role



8
9
10
11
# File 'lib/buildserver/role.rb', line 8

def initialize(role)
  @role         = role.to_s
  @build_blocks = []
end

Instance Attribute Details

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/buildserver/role.rb', line 6

def role
  @role
end

Instance Method Details

#add_build_block(block) ⇒ Object



13
14
15
# File 'lib/buildserver/role.rb', line 13

def add_build_block(block)
  @build_blocks << block
end

#build(roles) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/buildserver/role.rb', line 29

def build(roles)
  @commands       = []
  @after_commands = []

  # Safe bash:
  @commands << "set -eux"
  @commands << "set -o pipefail"

  @build_blocks.each do |build_block|
    @commands << "# ! #{build_block.to_s} -------------------------------------"

    commands, after_commands = build_block.build!(self, roles)

    @commands << commands
    @commands << "# / #{build_block.to_s} -------------------------------------"

    @after_commands << after_commands
  end

  @commands << @after_commands

  @commands << "if [ ! -f /root/system_setup_complete ]; then"
  @commands << "echo $(date \"+%Y.%m.%d-%H:%M:%S\") > /root/system_setup_complete"
  @commands << "fi"

  @commands.flatten
end

#external_portsObject



17
18
19
# File 'lib/buildserver/role.rb', line 17

def external_ports
  @build_blocks.map{|bb| bb.external_ports}.flatten
end

#has_role?(role) ⇒ Boolean



25
26
27
# File 'lib/buildserver/role.rb', line 25

def has_role?(role)
  @role == role.to_s
end

#internal_portsObject



21
22
23
# File 'lib/buildserver/role.rb', line 21

def internal_ports
  @build_blocks.map{|bb| bb.internal_ports}.flatten
end