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, Boot, Builder, Env, Healthcheck, Logging, Registry, Role, Servers, Ssh, Sshkit, Traefik, Validator, Volume
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.
45
46
47
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
|
# File 'lib/kamal/configuration.rb', line 45
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
@servers = Servers.new(config: self)
@registry = Registry.new(config: self)
@accessories = @raw_config.accessories&.keys&.collect { |name| Accessory.new(name, config: self) } || []
@boot = Boot.new(config: self)
@builder = Builder.new(config: self)
@env = Env.new(config: @raw_config.env || {})
@healthcheck = Healthcheck.new(healthcheck_config: @raw_config.healthcheck)
@logging = Logging.new(logging_config: @raw_config.logging)
@traefik = Traefik.new(config: self)
@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
end
|
Instance Attribute Details
#accessories ⇒ Object
Returns the value of attribute accessories.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def accessories
@accessories
end
|
#boot ⇒ Object
Returns the value of attribute boot.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def boot
@boot
end
|
#builder ⇒ Object
Returns the value of attribute builder.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def builder
@builder
end
|
#destination ⇒ Object
Returns the value of attribute destination.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def destination
@destination
end
|
#env ⇒ Object
Returns the value of attribute env.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def env
@env
end
|
#healthcheck ⇒ Object
Returns the value of attribute healthcheck.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def healthcheck
@healthcheck
end
|
#logging ⇒ Object
Returns the value of attribute logging.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def logging
@logging
end
|
#raw_config ⇒ Object
Returns the value of attribute raw_config.
13
14
15
|
# File 'lib/kamal/configuration.rb', line 13
def raw_config
@raw_config
end
|
#registry ⇒ Object
Returns the value of attribute registry.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def registry
@registry
end
|
#servers ⇒ Object
Returns the value of attribute servers.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def servers
@servers
end
|
#ssh ⇒ Object
Returns the value of attribute ssh.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def ssh
@ssh
end
|
#sshkit ⇒ Object
Returns the value of attribute sshkit.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def sshkit
@sshkit
end
|
#traefik ⇒ Object
Returns the value of attribute traefik.
14
15
16
|
# File 'lib/kamal/configuration.rb', line 14
def traefik
@traefik
end
|
Class Method Details
.create_from(config_file:, destination: nil, version: nil) ⇒ Object
19
20
21
22
23
|
# File 'lib/kamal/configuration.rb', line 19
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
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/kamal/configuration.rb', line 83
def abbreviated_version
if version
if version.include?("_")
version
else
version[0...7]
end
end
end
|
#absolute_image ⇒ Object
148
149
150
|
# File 'lib/kamal/configuration.rb', line 148
def absolute_image
"#{repository}:#{version}"
end
|
#accessory(name) ⇒ Object
107
108
109
|
# File 'lib/kamal/configuration.rb', line 107
def accessory(name)
accessories.detect { |a| a.name == name.to_s }
end
|
#all_hosts ⇒ Object
112
113
114
|
# File 'lib/kamal/configuration.rb', line 112
def all_hosts
(roles + accessories).flat_map(&:hosts).uniq
end
|
#allow_empty_roles? ⇒ Boolean
128
129
130
|
# File 'lib/kamal/configuration.rb', line 128
def allow_empty_roles?
raw_config.allow_empty_roles
end
|
#asset_path ⇒ Object
215
216
217
|
# File 'lib/kamal/configuration.rb', line 215
def asset_path
raw_config.asset_path
end
|
#env_tag(name) ⇒ Object
232
233
234
|
# File 'lib/kamal/configuration.rb', line 232
def env_tag(name)
env_tags.detect { |t| t.name == name.to_s }
end
|
224
225
226
227
228
229
230
|
# File 'lib/kamal/configuration.rb', line 224
def env_tags
@env_tags ||= if (tags = raw_config.env["tags"])
tags.collect { |name, config| Env::Tag.new(name, config: config) }
else
[]
end
end
|
#healthcheck_service ⇒ Object
186
187
188
|
# File 'lib/kamal/configuration.rb', line 186
def healthcheck_service
[ "healthcheck", service, destination ].compact.join("-")
end
|
#hooks_path ⇒ Object
211
212
213
|
# File 'lib/kamal/configuration.rb', line 211
def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end
|
#host_env_directory ⇒ Object
220
221
222
|
# File 'lib/kamal/configuration.rb', line 220
def host_env_directory
File.join(run_directory, "env")
end
|
#latest_image ⇒ Object
152
153
154
|
# File 'lib/kamal/configuration.rb', line 152
def latest_image
"#{repository}:#{latest_tag}"
end
|
#latest_tag ⇒ Object
156
157
158
|
# File 'lib/kamal/configuration.rb', line 156
def latest_tag
[ "latest", *destination ].join("-")
end
|
#logging_args ⇒ Object
181
182
183
|
# File 'lib/kamal/configuration.rb', line 181
def logging_args
logging.args
end
|
#minimum_version ⇒ Object
94
95
96
|
# File 'lib/kamal/configuration.rb', line 94
def minimum_version
raw_config.minimum_version
end
|
#primary_host ⇒ Object
116
117
118
|
# File 'lib/kamal/configuration.rb', line 116
def primary_host
primary_role&.primary_host
end
|
#primary_role ⇒ Object
124
125
126
|
# File 'lib/kamal/configuration.rb', line 124
def primary_role
role(primary_role_name)
end
|
#primary_role_name ⇒ Object
120
121
122
|
# File 'lib/kamal/configuration.rb', line 120
def primary_role_name
raw_config.primary_role || "web"
end
|
#readiness_delay ⇒ Object
190
191
192
|
# File 'lib/kamal/configuration.rb', line 190
def readiness_delay
raw_config.readiness_delay || 7
end
|
#repository ⇒ Object
144
145
146
|
# File 'lib/kamal/configuration.rb', line 144
def repository
[ registry.server, image ].compact.join("/")
end
|
#require_destination? ⇒ Boolean
164
165
166
|
# File 'lib/kamal/configuration.rb', line 164
def require_destination?
raw_config.require_destination
end
|
#retain_containers ⇒ Object
168
169
170
|
# File 'lib/kamal/configuration.rb', line 168
def retain_containers
raw_config.retain_containers || 5
end
|
#role(name) ⇒ Object
103
104
105
|
# File 'lib/kamal/configuration.rb', line 103
def role(name)
roles.detect { |r| r.name == name.to_s }
end
|
#roles ⇒ Object
99
100
101
|
# File 'lib/kamal/configuration.rb', line 99
def roles
servers.roles
end
|
#run_directory ⇒ Object
199
200
201
|
# File 'lib/kamal/configuration.rb', line 199
def run_directory
raw_config.run_directory || ".kamal"
end
|
#run_directory_as_docker_volume ⇒ Object
203
204
205
206
207
208
209
|
# File 'lib/kamal/configuration.rb', line 203
def run_directory_as_docker_volume
if Pathname.new(run_directory).absolute?
run_directory
else
File.join "$(pwd)", run_directory
end
end
|
#run_id ⇒ Object
194
195
196
|
# File 'lib/kamal/configuration.rb', line 194
def run_id
@run_id ||= SecureRandom.hex(16)
end
|
#service_with_version ⇒ Object
160
161
162
|
# File 'lib/kamal/configuration.rb', line 160
def service_with_version
"#{service}-#{version}"
end
|
#to_h ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/kamal/configuration.rb', line 237
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,
healthcheck: healthcheck.to_h
}.compact
end
|
#traefik_hosts ⇒ Object
140
141
142
|
# File 'lib/kamal/configuration.rb', line 140
def traefik_hosts
traefik_roles.flat_map(&:hosts).uniq
end
|
#traefik_role_names ⇒ Object
136
137
138
|
# File 'lib/kamal/configuration.rb', line 136
def traefik_role_names
traefik_roles.flat_map(&:name)
end
|
#traefik_roles ⇒ Object
132
133
134
|
# File 'lib/kamal/configuration.rb', line 132
def traefik_roles
roles.select(&:running_traefik?)
end
|
#version ⇒ Object
79
80
81
|
# File 'lib/kamal/configuration.rb', line 79
def version
@declared_version.presence || ENV["VERSION"] || git_version
end
|
#version=(version) ⇒ Object
75
76
77
|
# File 'lib/kamal/configuration.rb', line 75
def version=(version)
@declared_version = version
end
|
#volume_args ⇒ Object
173
174
175
176
177
178
179
|
# File 'lib/kamal/configuration.rb', line 173
def volume_args
if raw_config.volumes.present?
argumentize "--volume", raw_config.volumes
else
[]
end
end
|