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
Returns a new instance of 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
106
107
108
|
# File 'lib/kamal/configuration/accessory.rb', line 106
def cmd
accessory_config["cmd"]
end
|
#directories ⇒ Object
83
84
85
86
87
88
|
# File 'lib/kamal/configuration/accessory.rb', line 83
def directories
accessory_config["directories"]&.to_h do |host_to_container_mapping|
host_path, container_path = host_to_container_mapping.split(":")
[ expand_host_path(host_path), container_path ]
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
|
# File 'lib/kamal/configuration/accessory.rb', line 76
def files
accessory_config["files"]&.to_h do |local_to_remote_mapping|
local_file, remote_file = local_to_remote_mapping.split(":")
[ expand_local_file(local_file), expand_remote_file(remote_file) ]
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
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
98
99
100
101
102
103
104
|
# File 'lib/kamal/configuration/accessory.rb', line 98
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
110
111
112
|
# File 'lib/kamal/configuration/accessory.rb', line 110
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
94
95
96
|
# File 'lib/kamal/configuration/accessory.rb', line 94
def volume_args
argumentize "--volume", volumes
end
|
#volumes ⇒ Object
90
91
92
|
# File 'lib/kamal/configuration/accessory.rb', line 90
def volumes
specific_volumes + remote_files_as_volumes + remote_directories_as_volumes
end
|