Class: Kamal::Configuration::Role
- Inherits:
-
Object
- Object
- Kamal::Configuration::Role
show all
- Includes:
- Validation
- Defined in:
- lib/kamal/configuration/role.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Validation
#validate!, #validation_yml
Constructor Details
#initialize(name, config:) ⇒ Role
Returns a new instance of Role.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/kamal/configuration/role.rb', line 10
def initialize(name, config:)
@name, @config = name.inquiry, config
validate! \
specializations,
example: validation_yml["servers"]["workers"],
context: "servers/#{name}",
with: Kamal::Configuration::Validator::Role
@specialized_env = Kamal::Configuration::Env.new \
config: specializations.fetch("env", {}),
secrets: config.secrets,
context: "servers/#{name}/env"
@specialized_logging = Kamal::Configuration::Logging.new \
logging_config: specializations.fetch("logging", {}),
context: "servers/#{name}/logging"
initialize_specialized_proxy
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6
7
8
|
# File 'lib/kamal/configuration/role.rb', line 6
def config
@config
end
|
#name ⇒ Object
Also known as:
to_s
Returns the value of attribute name.
6
7
8
|
# File 'lib/kamal/configuration/role.rb', line 6
def name
@name
end
|
#specialized_env ⇒ Object
Returns the value of attribute specialized_env.
6
7
8
|
# File 'lib/kamal/configuration/role.rb', line 6
def specialized_env
@specialized_env
end
|
#specialized_logging ⇒ Object
Returns the value of attribute specialized_logging.
6
7
8
|
# File 'lib/kamal/configuration/role.rb', line 6
def specialized_logging
@specialized_logging
end
|
#specialized_proxy ⇒ Object
Returns the value of attribute specialized_proxy.
6
7
8
|
# File 'lib/kamal/configuration/role.rb', line 6
def specialized_proxy
@specialized_proxy
end
|
Instance Method Details
144
145
146
|
# File 'lib/kamal/configuration/role.rb', line 144
def (version = config.version)
File.join config.assets_directory, "extracted", [ name, version ].join("-")
end
|
#asset_path ⇒ Object
129
130
131
|
# File 'lib/kamal/configuration/role.rb', line 129
def asset_path
specializations["asset_path"] || config.asset_path
end
|
#asset_volume(version = config.version) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/kamal/configuration/role.rb', line 137
def asset_volume(version = config.version)
if assets?
Kamal::Configuration::Volume.new \
host_path: asset_volume_directory(version), container_path: asset_path
end
end
|
#asset_volume_args ⇒ Object
110
111
112
|
# File 'lib/kamal/configuration/role.rb', line 110
def asset_volume_args
asset_volume&.docker_args
end
|
#asset_volume_directory(version = config.version) ⇒ Object
148
149
150
|
# File 'lib/kamal/configuration/role.rb', line 148
def asset_volume_directory(version = config.version)
File.join config.assets_directory, "volumes", [ name, version ].join("-")
end
|
#assets? ⇒ Boolean
133
134
135
|
# File 'lib/kamal/configuration/role.rb', line 133
def assets?
asset_path.present? && running_proxy?
end
|
#cmd ⇒ Object
42
43
44
|
# File 'lib/kamal/configuration/role.rb', line 42
def cmd
specializations["cmd"]
end
|
#container_name(version = nil) ⇒ Object
120
121
122
|
# File 'lib/kamal/configuration/role.rb', line 120
def container_name(version = nil)
[ container_prefix, version || config.version ].compact.join("-")
end
|
#container_prefix ⇒ Object
124
125
126
|
# File 'lib/kamal/configuration/role.rb', line 124
def container_prefix
[ config.service, name, config.destination ].compact.join("-")
end
|
#ensure_one_host_for_ssl ⇒ Object
152
153
154
155
156
|
# File 'lib/kamal/configuration/role.rb', line 152
def ensure_one_host_for_ssl
if running_proxy? && proxy.ssl? && hosts.size > 1
raise Kamal::ConfigurationError, "SSL is only supported on a single server, found #{hosts.size} servers for role #{name}"
end
end
|
#env(host) ⇒ Object
89
90
91
92
|
# File 'lib/kamal/configuration/role.rb', line 89
def env(host)
@envs ||= {}
@envs[host] ||= [ config.env, specialized_env, *env_tags(host).map(&:env) ].reduce(:merge)
end
|
#env_args(host) ⇒ Object
94
95
96
|
# File 'lib/kamal/configuration/role.rb', line 94
def env_args(host)
[ *env(host).clear_args, *argumentize("--env-file", secrets_path) ]
end
|
#env_directory ⇒ Object
98
99
100
|
# File 'lib/kamal/configuration/role.rb', line 98
def env_directory
File.join(config.env_directory, "roles")
end
|
38
39
40
|
# File 'lib/kamal/configuration/role.rb', line 38
def env_tags(host)
tagged_hosts.fetch(host).collect { |tag| config.env_tag(tag) }
end
|
#hosts ⇒ Object
34
35
36
|
# File 'lib/kamal/configuration/role.rb', line 34
def hosts
tagged_hosts.keys
end
|
#label_args ⇒ Object
58
59
60
|
# File 'lib/kamal/configuration/role.rb', line 58
def label_args
argumentize "--label", labels
end
|
#labels ⇒ Object
54
55
56
|
# File 'lib/kamal/configuration/role.rb', line 54
def labels
default_labels.merge(custom_labels)
end
|
#logging ⇒ Object
66
67
68
|
# File 'lib/kamal/configuration/role.rb', line 66
def logging
@logging ||= config.logging.merge(specialized_logging)
end
|
#logging_args ⇒ Object
62
63
64
|
# File 'lib/kamal/configuration/role.rb', line 62
def logging_args
logging.args
end
|
#option_args ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/kamal/configuration/role.rb', line 46
def option_args
if args = specializations["options"]
optionize args
else
[]
end
end
|
#primary? ⇒ Boolean
115
116
117
|
# File 'lib/kamal/configuration/role.rb', line 115
def primary?
name == @config.primary_role_name
end
|
#primary_host ⇒ Object
30
31
32
|
# File 'lib/kamal/configuration/role.rb', line 30
def primary_host
hosts.first
end
|
#proxy ⇒ Object
70
71
72
|
# File 'lib/kamal/configuration/role.rb', line 70
def proxy
@proxy ||= config.proxy.merge(specialized_proxy) if running_proxy?
end
|
#running_proxy? ⇒ Boolean
74
75
76
|
# File 'lib/kamal/configuration/role.rb', line 74
def running_proxy?
@running_proxy
end
|
#secrets_io(host) ⇒ Object
102
103
104
|
# File 'lib/kamal/configuration/role.rb', line 102
def secrets_io(host)
env(host).secrets_io
end
|
#secrets_path ⇒ Object
106
107
108
|
# File 'lib/kamal/configuration/role.rb', line 106
def secrets_path
File.join(config.env_directory, "roles", "#{name}.env")
end
|
#ssl? ⇒ Boolean
78
79
80
|
# File 'lib/kamal/configuration/role.rb', line 78
def ssl?
running_proxy? && proxy.ssl?
end
|
#stop_args ⇒ Object
82
83
84
85
86
87
|
# File 'lib/kamal/configuration/role.rb', line 82
def stop_args
timeout = running_proxy? ? nil : config.drain_timeout
[ *argumentize("-t", timeout) ]
end
|