Class: Kamal::Configuration
- Inherits:
-
Object
- Object
- Kamal::Configuration
show all
- Includes:
- Validation
- Defined in:
- lib/kamal/configuration.rb
Defined Under Namespace
Modules: Validation
Classes: Accessory, Alias, Boot, Builder, Env, Logging, Proxy, Registry, Role, Servers, Ssh, Sshkit, Validator, Volume
Constant Summary
collapse
- PROXY_MINIMUM_VERSION =
"v0.6.0"
- PROXY_HTTP_PORT =
80
- PROXY_HTTPS_PORT =
443
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Validation
#validate!, #validation_yml
Constructor Details
#initialize(raw_config, destination: nil, version: nil, validate: true) ⇒ Configuration
Returns a new instance of Configuration.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/kamal/configuration.rb', line 48
def initialize(raw_config, destination: nil, version: nil, validate: true)
@raw_config = ActiveSupport::InheritableOptions.new(raw_config)
@destination = destination
@declared_version = version
validate! raw_config, example: validation_yml.symbolize_keys, context: "", with: Kamal::Configuration::Validator::Configuration
@secrets = Kamal::Secrets.new(destination: destination)
@servers = Servers.new(config: self)
@registry = Registry.new(config: self)
@accessories = @raw_config.accessories&.keys&.collect { |name| Accessory.new(name, config: self) } || []
@aliases = @raw_config.aliases&.keys&.to_h { |name| [ name, Alias.new(name, config: self) ] } || {}
@boot = Boot.new(config: self)
@builder = Builder.new(config: self)
@env = Env.new(config: @raw_config.env || {}, secrets: secrets)
@logging = Logging.new(logging_config: @raw_config.logging)
@proxy = Proxy.new(config: self, proxy_config: @raw_config.proxy || {})
@ssh = Ssh.new(config: self)
@sshkit = Sshkit.new(config: self)
ensure_destination_if_required
ensure_required_keys_present
ensure_valid_kamal_version
ensure_retain_containers_valid
ensure_valid_service_name
ensure_no_traefik_reboot_hooks
ensure_one_host_for_ssl_roles
ensure_unique_hosts_for_ssl_roles
end
|
Instance Attribute Details
#accessories ⇒ Object
Returns the value of attribute accessories.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def accessories
@accessories
end
|
#aliases ⇒ Object
Returns the value of attribute aliases.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def aliases
@aliases
end
|
#boot ⇒ Object
Returns the value of attribute boot.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def boot
@boot
end
|
#builder ⇒ Object
Returns the value of attribute builder.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def builder
@builder
end
|
#destination ⇒ Object
Returns the value of attribute destination.
12
13
14
|
# File 'lib/kamal/configuration.rb', line 12
def destination
@destination
end
|
#env ⇒ Object
Returns the value of attribute env.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def env
@env
end
|
#logging ⇒ Object
Returns the value of attribute logging.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def logging
@logging
end
|
#proxy ⇒ Object
Returns the value of attribute proxy.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def proxy
@proxy
end
|
#raw_config ⇒ Object
Returns the value of attribute raw_config.
12
13
14
|
# File 'lib/kamal/configuration.rb', line 12
def raw_config
@raw_config
end
|
#registry ⇒ Object
Returns the value of attribute registry.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def registry
@registry
end
|
#secrets ⇒ Object
Returns the value of attribute secrets.
12
13
14
|
# File 'lib/kamal/configuration.rb', line 12
def secrets
@secrets
end
|
#servers ⇒ Object
Returns the value of attribute servers.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def servers
@servers
end
|
#ssh ⇒ Object
Returns the value of attribute ssh.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def ssh
@ssh
end
|
#sshkit ⇒ Object
Returns the value of attribute sshkit.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def sshkit
@sshkit
end
|
Class Method Details
.create_from(config_file:, destination: nil, version: nil) ⇒ Object
22
23
24
25
26
|
# File 'lib/kamal/configuration.rb', line 22
def create_from(config_file:, destination: nil, version: nil)
raw_config = load_config_files(config_file, *destination_config_file(config_file, destination))
new raw_config, destination: destination, version: version
end
|
Instance Method Details
#abbreviated_version ⇒ Object
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/kamal/configuration.rb', line 91
def abbreviated_version
if version
if version.include?("_")
version
else
version[0...7]
end
end
end
|
#absolute_image ⇒ Object
156
157
158
|
# File 'lib/kamal/configuration.rb', line 156
def absolute_image
"#{repository}:#{version}"
end
|
#accessory(name) ⇒ Object
115
116
117
|
# File 'lib/kamal/configuration.rb', line 115
def accessory(name)
accessories.detect { |a| a.name == name.to_s }
end
|
#all_hosts ⇒ Object
120
121
122
|
# File 'lib/kamal/configuration.rb', line 120
def all_hosts
(roles + accessories).flat_map(&:hosts).uniq
end
|
#allow_empty_roles? ⇒ Boolean
136
137
138
|
# File 'lib/kamal/configuration.rb', line 136
def allow_empty_roles?
raw_config.allow_empty_roles
end
|
#app_directory ⇒ Object
215
216
217
|
# File 'lib/kamal/configuration.rb', line 215
def app_directory
File.join apps_directory, [ service, destination ].compact.join("-")
end
|
#apps_directory ⇒ Object
211
212
213
|
# File 'lib/kamal/configuration.rb', line 211
def apps_directory
File.join run_directory, "apps"
end
|
#asset_path ⇒ Object
232
233
234
|
# File 'lib/kamal/configuration.rb', line 232
def asset_path
raw_config.asset_path
end
|
#assets_directory ⇒ Object
223
224
225
|
# File 'lib/kamal/configuration.rb', line 223
def assets_directory
File.join app_directory, "assets"
end
|
#deploy_timeout ⇒ Object
198
199
200
|
# File 'lib/kamal/configuration.rb', line 198
def deploy_timeout
raw_config.deploy_timeout || 30
end
|
#drain_timeout ⇒ Object
202
203
204
|
# File 'lib/kamal/configuration.rb', line 202
def drain_timeout
raw_config.drain_timeout || 30
end
|
#env_directory ⇒ Object
219
220
221
|
# File 'lib/kamal/configuration.rb', line 219
def env_directory
File.join app_directory, "env"
end
|
#env_tag(name) ⇒ Object
245
246
247
|
# File 'lib/kamal/configuration.rb', line 245
def env_tag(name)
env_tags.detect { |t| t.name == name.to_s }
end
|
237
238
239
240
241
242
243
|
# File 'lib/kamal/configuration.rb', line 237
def env_tags
@env_tags ||= if (tags = raw_config.env["tags"])
tags.collect { |name, config| Env::Tag.new(name, config: config, secrets: secrets) }
else
[]
end
end
|
#hooks_path ⇒ Object
228
229
230
|
# File 'lib/kamal/configuration.rb', line 228
def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end
|
#latest_image ⇒ Object
160
161
162
|
# File 'lib/kamal/configuration.rb', line 160
def latest_image
"#{repository}:#{latest_tag}"
end
|
#latest_tag ⇒ Object
164
165
166
|
# File 'lib/kamal/configuration.rb', line 164
def latest_tag
[ "latest", *destination ].join("-")
end
|
#logging_args ⇒ Object
189
190
191
|
# File 'lib/kamal/configuration.rb', line 189
def logging_args
logging.args
end
|
#minimum_version ⇒ Object
102
103
104
|
# File 'lib/kamal/configuration.rb', line 102
def minimum_version
raw_config.minimum_version
end
|
#primary_host ⇒ Object
124
125
126
|
# File 'lib/kamal/configuration.rb', line 124
def primary_host
primary_role&.primary_host
end
|
#primary_role ⇒ Object
132
133
134
|
# File 'lib/kamal/configuration.rb', line 132
def primary_role
role(primary_role_name)
end
|
#primary_role_name ⇒ Object
128
129
130
|
# File 'lib/kamal/configuration.rb', line 128
def primary_role_name
raw_config.primary_role || "web"
end
|
#proxy_container_name ⇒ Object
261
262
263
|
# File 'lib/kamal/configuration.rb', line 261
def proxy_container_name
"kamal-proxy"
end
|
#proxy_directory ⇒ Object
265
266
267
|
# File 'lib/kamal/configuration.rb', line 265
def proxy_directory
File.join run_directory, "proxy"
end
|
#proxy_hosts ⇒ Object
148
149
150
|
# File 'lib/kamal/configuration.rb', line 148
def proxy_hosts
proxy_roles.flat_map(&:hosts).uniq
end
|
#proxy_image ⇒ Object
257
258
259
|
# File 'lib/kamal/configuration.rb', line 257
def proxy_image
"basecamp/kamal-proxy:#{PROXY_MINIMUM_VERSION}"
end
|
#proxy_options_default ⇒ Object
253
254
255
|
# File 'lib/kamal/configuration.rb', line 253
def proxy_options_default
proxy_publish_args PROXY_HTTP_PORT, PROXY_HTTPS_PORT
end
|
#proxy_options_file ⇒ Object
269
270
271
|
# File 'lib/kamal/configuration.rb', line 269
def proxy_options_file
File.join proxy_directory, "options"
end
|
#proxy_publish_args(http_port, https_port) ⇒ Object
249
250
251
|
# File 'lib/kamal/configuration.rb', line 249
def proxy_publish_args(http_port, https_port)
argumentize "--publish", [ "#{http_port}:#{PROXY_HTTP_PORT}", "#{https_port}:#{PROXY_HTTPS_PORT}" ]
end
|
#proxy_role_names ⇒ Object
144
145
146
|
# File 'lib/kamal/configuration.rb', line 144
def proxy_role_names
proxy_roles.flat_map(&:name)
end
|
#proxy_roles ⇒ Object
140
141
142
|
# File 'lib/kamal/configuration.rb', line 140
def proxy_roles
roles.select(&:running_proxy?)
end
|
#readiness_delay ⇒ Object
194
195
196
|
# File 'lib/kamal/configuration.rb', line 194
def readiness_delay
raw_config.readiness_delay || 7
end
|
#repository ⇒ Object
152
153
154
|
# File 'lib/kamal/configuration.rb', line 152
def repository
[ registry.server, image ].compact.join("/")
end
|
#require_destination? ⇒ Boolean
172
173
174
|
# File 'lib/kamal/configuration.rb', line 172
def require_destination?
raw_config.require_destination
end
|
#retain_containers ⇒ Object
176
177
178
|
# File 'lib/kamal/configuration.rb', line 176
def retain_containers
raw_config.retain_containers || 5
end
|
#role(name) ⇒ Object
111
112
113
|
# File 'lib/kamal/configuration.rb', line 111
def role(name)
roles.detect { |r| r.name == name.to_s }
end
|
#roles ⇒ Object
107
108
109
|
# File 'lib/kamal/configuration.rb', line 107
def roles
servers.roles
end
|
#run_directory ⇒ Object
207
208
209
|
# File 'lib/kamal/configuration.rb', line 207
def run_directory
".kamal"
end
|
#service_with_version ⇒ Object
168
169
170
|
# File 'lib/kamal/configuration.rb', line 168
def service_with_version
"#{service}-#{version}"
end
|
#to_h ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/kamal/configuration.rb', line 274
def to_h
{
roles: role_names,
hosts: all_hosts,
primary_host: primary_host,
version: version,
repository: repository,
absolute_image: absolute_image,
service_with_version: service_with_version,
volume_args: volume_args,
ssh_options: ssh.to_h,
sshkit: sshkit.to_h,
builder: builder.to_h,
accessories: raw_config.accessories,
logging: logging_args
}.compact
end
|
#version ⇒ Object
87
88
89
|
# File 'lib/kamal/configuration.rb', line 87
def version
@declared_version.presence || ENV["VERSION"] || git_version
end
|
#version=(version) ⇒ Object
83
84
85
|
# File 'lib/kamal/configuration.rb', line 83
def version=(version)
@declared_version = version
end
|
#volume_args ⇒ Object
181
182
183
184
185
186
187
|
# File 'lib/kamal/configuration.rb', line 181
def volume_args
if raw_config.volumes.present?
argumentize "--volume", raw_config.volumes
else
[]
end
end
|