Class: Kamal::Configuration
- Inherits:
-
Object
- Object
- Kamal::Configuration
show all
- Defined in:
- lib/kamal/configuration.rb
Defined Under Namespace
Classes: Accessory, Boot, Builder, Role, Ssh, Sshkit, Volume
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw_config, destination: nil, version: nil, validate: true) ⇒ Configuration
Returns a new instance of Configuration.
41
42
43
44
45
46
|
# File 'lib/kamal/configuration.rb', line 41
def initialize(raw_config, destination: nil, version: nil, validate: true)
@raw_config = ActiveSupport::InheritableOptions.new(raw_config)
@destination = destination
@declared_version = version
valid? if validate
end
|
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
12
13
14
|
# File 'lib/kamal/configuration.rb', line 12
def destination
@destination
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
|
Class Method Details
.create_from(config_file:, destination: nil, version: nil) ⇒ Object
15
16
17
18
19
|
# File 'lib/kamal/configuration.rb', line 15
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
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/kamal/configuration.rb', line 57
def abbreviated_version
if version
if version.include?("_")
version
else
version[0...7]
end
end
end
|
#absolute_image ⇒ Object
114
115
116
|
# File 'lib/kamal/configuration.rb', line 114
def absolute_image
"#{repository}:#{version}"
end
|
#accessories ⇒ Object
81
82
83
|
# File 'lib/kamal/configuration.rb', line 81
def accessories
@accessories ||= raw_config.accessories&.keys&.collect { |name| Kamal::Configuration::Accessory.new(name, config: self) } || []
end
|
#accessory(name) ⇒ Object
85
86
87
|
# File 'lib/kamal/configuration.rb', line 85
def accessory(name)
accessories.detect { |a| a.name == name.to_s }
end
|
#all_hosts ⇒ Object
90
91
92
|
# File 'lib/kamal/configuration.rb', line 90
def all_hosts
roles.flat_map(&:hosts).uniq
end
|
#allow_empty_roles? ⇒ Boolean
215
216
217
|
# File 'lib/kamal/configuration.rb', line 215
def allow_empty_roles?
raw_config.allow_empty_roles
end
|
#asset_path ⇒ Object
207
208
209
|
# File 'lib/kamal/configuration.rb', line 207
def asset_path
raw_config.asset_path
end
|
#healthcheck ⇒ Object
170
171
172
|
# File 'lib/kamal/configuration.rb', line 170
def healthcheck
{ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }.merge(raw_config.healthcheck || {})
end
|
#healthcheck_service ⇒ Object
174
175
176
|
# File 'lib/kamal/configuration.rb', line 174
def healthcheck_service
[ "healthcheck", service, destination ].compact.join("-")
end
|
#hooks_path ⇒ Object
199
200
201
|
# File 'lib/kamal/configuration.rb', line 199
def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end
|
#host_env_directory ⇒ Object
203
204
205
|
# File 'lib/kamal/configuration.rb', line 203
def host_env_directory
"#{run_directory}/env"
end
|
#latest_image ⇒ Object
118
119
120
|
# File 'lib/kamal/configuration.rb', line 118
def latest_image
"#{repository}:latest"
end
|
#logging_args ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'lib/kamal/configuration.rb', line 139
def logging_args
if raw_config.logging.present?
optionize({ "log-driver" => raw_config.logging["driver"] }.compact) +
argumentize("--log-opt", raw_config.logging["options"])
else
argumentize("--log-opt", { "max-size" => "10m" })
end
end
|
#minimum_version ⇒ Object
68
69
70
|
# File 'lib/kamal/configuration.rb', line 68
def minimum_version
raw_config.minimum_version
end
|
#primary_web_host ⇒ Object
94
95
96
|
# File 'lib/kamal/configuration.rb', line 94
def primary_web_host
role(primary_web_role)&.primary_host
end
|
#primary_web_role ⇒ Object
211
212
213
|
# File 'lib/kamal/configuration.rb', line 211
def primary_web_role
raw_config.primary_web_role || "web"
end
|
#readiness_delay ⇒ Object
178
179
180
|
# File 'lib/kamal/configuration.rb', line 178
def readiness_delay
raw_config.readiness_delay || 7
end
|
#repository ⇒ Object
110
111
112
|
# File 'lib/kamal/configuration.rb', line 110
def repository
[ raw_config.registry["server"], image ].compact.join("/")
end
|
#require_destination? ⇒ Boolean
126
127
128
|
# File 'lib/kamal/configuration.rb', line 126
def require_destination?
raw_config.require_destination
end
|
#role(name) ⇒ Object
77
78
79
|
# File 'lib/kamal/configuration.rb', line 77
def role(name)
roles.detect { |r| r.name == name.to_s }
end
|
#roles ⇒ Object
73
74
75
|
# File 'lib/kamal/configuration.rb', line 73
def roles
@roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) }
end
|
#run_directory ⇒ Object
187
188
189
|
# File 'lib/kamal/configuration.rb', line 187
def run_directory
raw_config.run_directory || ".kamal"
end
|
#run_directory_as_docker_volume ⇒ Object
191
192
193
194
195
196
197
|
# File 'lib/kamal/configuration.rb', line 191
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
182
183
184
|
# File 'lib/kamal/configuration.rb', line 182
def run_id
@run_id ||= SecureRandom.hex(16)
end
|
#service_with_version ⇒ Object
122
123
124
|
# File 'lib/kamal/configuration.rb', line 122
def service_with_version
"#{service}-#{version}"
end
|
#to_h ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/kamal/configuration.rb', line 224
def to_h
{
roles: role_names,
hosts: all_hosts,
primary_host: primary_web_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
}.compact
end
|
#traefik ⇒ Object
157
158
159
|
# File 'lib/kamal/configuration.rb', line 157
def traefik
raw_config.traefik || {}
end
|
#traefik_hosts ⇒ Object
106
107
108
|
# File 'lib/kamal/configuration.rb', line 106
def traefik_hosts
traefik_roles.flat_map(&:hosts).uniq
end
|
#traefik_role_names ⇒ Object
102
103
104
|
# File 'lib/kamal/configuration.rb', line 102
def traefik_role_names
traefik_roles.flat_map(&:name)
end
|
#traefik_roles ⇒ Object
98
99
100
|
# File 'lib/kamal/configuration.rb', line 98
def traefik_roles
roles.select(&:running_traefik?)
end
|
#valid? ⇒ Boolean
220
221
222
|
# File 'lib/kamal/configuration.rb', line 220
def valid?
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version
end
|
#version ⇒ Object
53
54
55
|
# File 'lib/kamal/configuration.rb', line 53
def version
@declared_version.presence || ENV["VERSION"] || git_version
end
|
#version=(version) ⇒ Object
49
50
51
|
# File 'lib/kamal/configuration.rb', line 49
def version=(version)
@declared_version = version
end
|
#volume_args ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/kamal/configuration.rb', line 131
def volume_args
if raw_config.volumes.present?
argumentize "--volume", raw_config.volumes
else
[]
end
end
|