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
|
# 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"
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
|
Instance Method Details
#cmd ⇒ Object
105
106
107
|
# File 'lib/kamal/configuration/accessory.rb', line 105
def cmd
accessory_config["cmd"]
end
|
#directories ⇒ Object
82
83
84
85
86
87
|
# File 'lib/kamal/configuration/accessory.rb', line 82
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
59
60
61
|
# File 'lib/kamal/configuration/accessory.rb', line 59
def env_args
[ *env.clear_args, *argumentize("--env-file", secrets_path) ]
end
|
#env_directory ⇒ Object
63
64
65
|
# File 'lib/kamal/configuration/accessory.rb', line 63
def env_directory
File.join(config.env_directory, "accessories")
end
|
#files ⇒ Object
75
76
77
78
79
80
|
# File 'lib/kamal/configuration/accessory.rb', line 75
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
33
34
35
|
# File 'lib/kamal/configuration/accessory.rb', line 33
def hosts
hosts_from_host || hosts_from_hosts || hosts_from_roles
end
|
#image ⇒ Object
29
30
31
|
# File 'lib/kamal/configuration/accessory.rb', line 29
def image
accessory_config["image"]
end
|
#label_args ⇒ Object
55
56
57
|
# File 'lib/kamal/configuration/accessory.rb', line 55
def label_args
argumentize "--label", labels
end
|
#labels ⇒ Object
51
52
53
|
# File 'lib/kamal/configuration/accessory.rb', line 51
def labels
default_labels.merge(accessory_config["labels"] || {})
end
|
#network_args ⇒ Object
43
44
45
|
# File 'lib/kamal/configuration/accessory.rb', line 43
def network_args
argumentize "--network", network
end
|
#option_args ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/kamal/configuration/accessory.rb', line 97
def option_args
if args = accessory_config["options"]
optionize args
else
[]
end
end
|
#port ⇒ Object
37
38
39
40
41
|
# File 'lib/kamal/configuration/accessory.rb', line 37
def port
if port = accessory_config["port"]&.to_s
port.include?(":") ? port : "#{port}:#{port}"
end
end
|
#publish_args ⇒ Object
47
48
49
|
# File 'lib/kamal/configuration/accessory.rb', line 47
def publish_args
argumentize "--publish", port if port
end
|
#secrets_io ⇒ Object
67
68
69
|
# File 'lib/kamal/configuration/accessory.rb', line 67
def secrets_io
env.secrets_io
end
|
#secrets_path ⇒ Object
71
72
73
|
# File 'lib/kamal/configuration/accessory.rb', line 71
def secrets_path
File.join(config.env_directory, "accessories", "#{name}.env")
end
|
#service_name ⇒ Object
25
26
27
|
# File 'lib/kamal/configuration/accessory.rb', line 25
def service_name
accessory_config["service"] || "#{config.service}-#{name}"
end
|
#volume_args ⇒ Object
93
94
95
|
# File 'lib/kamal/configuration/accessory.rb', line 93
def volume_args
argumentize "--volume", volumes
end
|
#volumes ⇒ Object
89
90
91
|
# File 'lib/kamal/configuration/accessory.rb', line 89
def volumes
specific_volumes + remote_files_as_volumes + remote_directories_as_volumes
end
|