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.
39
40
41
42
43
44
|
# File 'lib/kamal/configuration.rb', line 39
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
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/kamal/configuration.rb', line 55
def abbreviated_version
if version
if version.include?("_")
version
else
version[0...7]
end
end
end
|
#absolute_image ⇒ Object
105
106
107
|
# File 'lib/kamal/configuration.rb', line 105
def absolute_image
"#{repository}:#{version}"
end
|
#accessories ⇒ Object
79
80
81
|
# File 'lib/kamal/configuration.rb', line 79
def accessories
@accessories ||= raw_config.accessories&.keys&.collect { |name| Kamal::Configuration::Accessory.new(name, config: self) } || []
end
|
#accessory(name) ⇒ Object
83
84
85
|
# File 'lib/kamal/configuration.rb', line 83
def accessory(name)
accessories.detect { |a| a.name == name.to_s }
end
|
#all_hosts ⇒ Object
88
89
90
|
# File 'lib/kamal/configuration.rb', line 88
def all_hosts
roles.flat_map(&:hosts).uniq
end
|
#asset_path ⇒ Object
198
199
200
|
# File 'lib/kamal/configuration.rb', line 198
def asset_path
raw_config.asset_path
end
|
#boot ⇒ Object
140
141
142
|
# File 'lib/kamal/configuration.rb', line 140
def boot
Kamal::Configuration::Boot.new(config: self)
end
|
#builder ⇒ Object
144
145
146
|
# File 'lib/kamal/configuration.rb', line 144
def builder
Kamal::Configuration::Builder.new(config: self)
end
|
#healthcheck ⇒ Object
161
162
163
|
# File 'lib/kamal/configuration.rb', line 161
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
165
166
167
|
# File 'lib/kamal/configuration.rb', line 165
def healthcheck_service
[ "healthcheck", service, destination ].compact.join("-")
end
|
#hooks_path ⇒ Object
190
191
192
|
# File 'lib/kamal/configuration.rb', line 190
def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end
|
#host_env_directory ⇒ Object
194
195
196
|
# File 'lib/kamal/configuration.rb', line 194
def host_env_directory
"#{run_directory}/env"
end
|
#latest_image ⇒ Object
109
110
111
|
# File 'lib/kamal/configuration.rb', line 109
def latest_image
"#{repository}:latest"
end
|
#logging_args ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/kamal/configuration.rb', line 130
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
66
67
68
|
# File 'lib/kamal/configuration.rb', line 66
def minimum_version
raw_config.minimum_version
end
|
#primary_web_host ⇒ Object
92
93
94
|
# File 'lib/kamal/configuration.rb', line 92
def primary_web_host
role(:web).primary_host
end
|
#readiness_delay ⇒ Object
169
170
171
|
# File 'lib/kamal/configuration.rb', line 169
def readiness_delay
raw_config.readiness_delay || 7
end
|
#repository ⇒ Object
101
102
103
|
# File 'lib/kamal/configuration.rb', line 101
def repository
[ raw_config.registry["server"], image ].compact.join("/")
end
|
#require_destination? ⇒ Boolean
117
118
119
|
# File 'lib/kamal/configuration.rb', line 117
def require_destination?
raw_config.require_destination
end
|
#role(name) ⇒ Object
75
76
77
|
# File 'lib/kamal/configuration.rb', line 75
def role(name)
roles.detect { |r| r.name == name.to_s }
end
|
#roles ⇒ Object
71
72
73
|
# File 'lib/kamal/configuration.rb', line 71
def roles
@roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) }
end
|
#run_directory ⇒ Object
178
179
180
|
# File 'lib/kamal/configuration.rb', line 178
def run_directory
raw_config.run_directory || ".kamal"
end
|
#run_directory_as_docker_volume ⇒ Object
182
183
184
185
186
187
188
|
# File 'lib/kamal/configuration.rb', line 182
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
173
174
175
|
# File 'lib/kamal/configuration.rb', line 173
def run_id
@run_id ||= SecureRandom.hex(16)
end
|
#service_with_version ⇒ Object
113
114
115
|
# File 'lib/kamal/configuration.rb', line 113
def service_with_version
"#{service}-#{version}"
end
|
#ssh ⇒ Object
152
153
154
|
# File 'lib/kamal/configuration.rb', line 152
def ssh
Kamal::Configuration::Ssh.new(config: self)
end
|
#sshkit ⇒ Object
156
157
158
|
# File 'lib/kamal/configuration.rb', line 156
def sshkit
Kamal::Configuration::Sshkit.new(config: self)
end
|
#to_h ⇒ Object
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/kamal/configuration.rb', line 207
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
148
149
150
|
# File 'lib/kamal/configuration.rb', line 148
def traefik
raw_config.traefik || {}
end
|
#traefik_hosts ⇒ Object
96
97
98
|
# File 'lib/kamal/configuration.rb', line 96
def traefik_hosts
roles.select(&:running_traefik?).flat_map(&:hosts).uniq
end
|
#valid? ⇒ Boolean
203
204
205
|
# File 'lib/kamal/configuration.rb', line 203
def valid?
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version
end
|
#version ⇒ Object
51
52
53
|
# File 'lib/kamal/configuration.rb', line 51
def version
@declared_version.presence || ENV["VERSION"] || git_version
end
|
#version=(version) ⇒ Object
47
48
49
|
# File 'lib/kamal/configuration.rb', line 47
def version=(version)
@declared_version = version
end
|
#volume_args ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/kamal/configuration.rb', line 122
def volume_args
if raw_config.volumes.present?
argumentize "--volume", raw_config.volumes
else
[]
end
end
|