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
25
|
# 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
@env = Kamal::Configuration::Env.new \
config: accessory_config.fetch("env", {}),
secrets: config.secrets,
context: "accessories/#{name}/env"
initialize_proxy if running_proxy?
end
|
Instance Attribute Details
#accessory_config ⇒ Object
Returns the value of attribute accessory_config.
8
9
10
|
# File 'lib/kamal/configuration/accessory.rb', line 8
def accessory_config
@accessory_config
end
|
#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
|
Instance Method Details
#cmd ⇒ Object
107
108
109
|
# File 'lib/kamal/configuration/accessory.rb', line 107
def cmd
accessory_config["cmd"]
end
|
#directories ⇒ Object
84
85
86
87
88
89
|
# File 'lib/kamal/configuration/accessory.rb', line 84
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
61
62
63
|
# File 'lib/kamal/configuration/accessory.rb', line 61
def env_args
[ *env.clear_args, *argumentize("--env-file", secrets_path) ]
end
|
#env_directory ⇒ Object
65
66
67
|
# File 'lib/kamal/configuration/accessory.rb', line 65
def env_directory
File.join(config.env_directory, "accessories")
end
|
#files ⇒ Object
77
78
79
80
81
82
|
# File 'lib/kamal/configuration/accessory.rb', line 77
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
35
36
37
|
# File 'lib/kamal/configuration/accessory.rb', line 35
def hosts
hosts_from_host || hosts_from_hosts || hosts_from_roles
end
|
#image ⇒ Object
31
32
33
|
# File 'lib/kamal/configuration/accessory.rb', line 31
def image
accessory_config["image"]
end
|
#initialize_proxy ⇒ Object
115
116
117
118
119
120
|
# File 'lib/kamal/configuration/accessory.rb', line 115
def initialize_proxy
@proxy = Kamal::Configuration::Proxy.new \
config: config,
proxy_config: accessory_config["proxy"],
context: "accessories/#{name}/proxy"
end
|
#label_args ⇒ Object
57
58
59
|
# File 'lib/kamal/configuration/accessory.rb', line 57
def label_args
argumentize "--label", labels
end
|
#labels ⇒ Object
53
54
55
|
# File 'lib/kamal/configuration/accessory.rb', line 53
def labels
default_labels.merge(accessory_config["labels"] || {})
end
|
#network_args ⇒ Object
45
46
47
|
# File 'lib/kamal/configuration/accessory.rb', line 45
def network_args
argumentize "--network", network
end
|
#option_args ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/kamal/configuration/accessory.rb', line 99
def option_args
if args = accessory_config["options"]
optionize args
else
[]
end
end
|
#port ⇒ Object
39
40
41
42
43
|
# File 'lib/kamal/configuration/accessory.rb', line 39
def port
if port = accessory_config["port"]&.to_s
port.include?(":") ? port : "#{port}:#{port}"
end
end
|
#publish_args ⇒ Object
49
50
51
|
# File 'lib/kamal/configuration/accessory.rb', line 49
def publish_args
argumentize "--publish", port if port
end
|
#running_proxy? ⇒ Boolean
111
112
113
|
# File 'lib/kamal/configuration/accessory.rb', line 111
def running_proxy?
@accessory_config["proxy"].present?
end
|
#secrets_io ⇒ Object
69
70
71
|
# File 'lib/kamal/configuration/accessory.rb', line 69
def secrets_io
env.secrets_io
end
|
#secrets_path ⇒ Object
73
74
75
|
# File 'lib/kamal/configuration/accessory.rb', line 73
def secrets_path
File.join(config.env_directory, "accessories", "#{name}.env")
end
|
#service_name ⇒ Object
27
28
29
|
# File 'lib/kamal/configuration/accessory.rb', line 27
def service_name
accessory_config["service"] || "#{config.service}-#{name}"
end
|
#volume_args ⇒ Object
95
96
97
|
# File 'lib/kamal/configuration/accessory.rb', line 95
def volume_args
argumentize "--volume", volumes
end
|
#volumes ⇒ Object
91
92
93
|
# File 'lib/kamal/configuration/accessory.rb', line 91
def volumes
specific_volumes + remote_files_as_volumes + remote_directories_as_volumes
end
|