Class: Kamal::Configuration::Accessory
- Inherits:
-
Object
- Object
- Kamal::Configuration::Accessory
show all
- Includes:
- Validation
- Defined in:
- lib/kamal/configuration/accessory.rb
Constant Summary
collapse
- DEFAULT_NETWORK =
"kamal"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Validation
#validate!, #validation_yml
Constructor Details
#initialize(name, config:) ⇒ Accessory
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/kamal/configuration/accessory.rb', line 10
def initialize(name, config:)
@name, @config, @accessory_config = name.inquiry, config, config.raw_config["accessories"][name]
validate! \
accessory_config,
example: validation_yml["accessories"]["mysql"],
context: "accessories/#{name}",
with: Kamal::Configuration::Validator::Accessory
ensure_valid_roles
@env = initialize_env
@proxy = initialize_proxy if running_proxy?
@registry = initialize_registry if accessory_config["registry"].present?
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
8
9
10
|
# File 'lib/kamal/configuration/accessory.rb', line 8
def env
@env
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/kamal/configuration/accessory.rb', line 8
def name
@name
end
|
#proxy ⇒ Object
Returns the value of attribute proxy.
8
9
10
|
# File 'lib/kamal/configuration/accessory.rb', line 8
def proxy
@proxy
end
|
#registry ⇒ Object
Returns the value of attribute registry.
8
9
10
|
# File 'lib/kamal/configuration/accessory.rb', line 8
def registry
@registry
end
|
Instance Method Details
#cmd ⇒ Object
112
113
114
|
# File 'lib/kamal/configuration/accessory.rb', line 112
def cmd
accessory_config["cmd"]
end
|
#directories ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/kamal/configuration/accessory.rb', line 88
def directories
accessory_config["directories"]&.to_h do |config|
parse_path_config(config, default_mode: nil) do |local, remote|
{
key: expand_host_path(local),
host_path: expand_host_path_for_volume(local),
container_path: remote
}
end
end || {}
end
|
#env_args ⇒ Object
60
61
62
|
# File 'lib/kamal/configuration/accessory.rb', line 60
def env_args
[ *env.clear_args, *argumentize("--env-file", secrets_path) ]
end
|
#env_directory ⇒ Object
64
65
66
|
# File 'lib/kamal/configuration/accessory.rb', line 64
def env_directory
File.join(config.env_directory, "accessories")
end
|
#files ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/kamal/configuration/accessory.rb', line 76
def files
accessory_config["files"]&.to_h do |config|
parse_path_config(config, default_mode: "755") do |local, remote|
{
key: expand_local_file(local),
host_path: expand_remote_file(remote),
container_path: remote
}
end
end || {}
end
|
#hosts ⇒ Object
34
35
36
|
# File 'lib/kamal/configuration/accessory.rb', line 34
def hosts
hosts_from_host || hosts_from_hosts || hosts_from_roles || hosts_from_tags
end
|
#image ⇒ Object
30
31
32
|
# File 'lib/kamal/configuration/accessory.rb', line 30
def image
[ registry&.server, accessory_config["image"] ].compact.join("/")
end
|
#label_args ⇒ Object
56
57
58
|
# File 'lib/kamal/configuration/accessory.rb', line 56
def label_args
argumentize "--label", labels
end
|
#labels ⇒ Object
52
53
54
|
# File 'lib/kamal/configuration/accessory.rb', line 52
def labels
default_labels.merge(accessory_config["labels"] || {})
end
|
#network_args ⇒ Object
44
45
46
|
# File 'lib/kamal/configuration/accessory.rb', line 44
def network_args
argumentize "--network", network
end
|
#option_args ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/kamal/configuration/accessory.rb', line 104
def option_args
if args = accessory_config["options"]
optionize args
else
[]
end
end
|
#port ⇒ Object
38
39
40
41
42
|
# File 'lib/kamal/configuration/accessory.rb', line 38
def port
if port = accessory_config["port"]&.to_s
port.include?(":") ? port : "#{port}:#{port}"
end
end
|
#publish_args ⇒ Object
48
49
50
|
# File 'lib/kamal/configuration/accessory.rb', line 48
def publish_args
argumentize "--publish", port if port
end
|
#running_proxy? ⇒ Boolean
116
117
118
|
# File 'lib/kamal/configuration/accessory.rb', line 116
def running_proxy?
accessory_config["proxy"].present?
end
|
#secrets_io ⇒ Object
68
69
70
|
# File 'lib/kamal/configuration/accessory.rb', line 68
def secrets_io
env.secrets_io
end
|
#secrets_path ⇒ Object
72
73
74
|
# File 'lib/kamal/configuration/accessory.rb', line 72
def secrets_path
File.join(config.env_directory, "accessories", "#{name}.env")
end
|
#service_name ⇒ Object
26
27
28
|
# File 'lib/kamal/configuration/accessory.rb', line 26
def service_name
accessory_config["service"] || "#{config.service}-#{name}"
end
|
#volume_args ⇒ Object
100
101
102
|
# File 'lib/kamal/configuration/accessory.rb', line 100
def volume_args
argumentize("--volume", specific_volumes) + (path_volumes(files) + path_volumes(directories)).flat_map(&:docker_args)
end
|