Class: Kamal::Configuration::Accessory
- Inherits:
-
Object
- Object
- Kamal::Configuration::Accessory
- Includes:
- Validation
- Defined in:
- lib/kamal/configuration/accessory.rb
Instance Attribute Summary collapse
-
#accessory_config ⇒ Object
readonly
Returns the value of attribute accessory_config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #cmd ⇒ Object
- #directories ⇒ Object
- #env_args ⇒ Object
- #files ⇒ Object
- #hosts ⇒ Object
- #image ⇒ Object
-
#initialize(name, config:) ⇒ Accessory
constructor
A new instance of Accessory.
- #label_args ⇒ Object
- #labels ⇒ Object
- #option_args ⇒ Object
- #port ⇒ Object
- #publish_args ⇒ Object
- #service_name ⇒ Object
- #volume_args ⇒ Object
- #volumes ⇒ Object
Methods included from Validation
Constructor Details
#initialize(name, config:) ⇒ Accessory
Returns a new instance of Accessory.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kamal/configuration/accessory.rb', line 8 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_file: File.join(config.host_env_directory, "accessories", "#{service_name}.env"), context: "accessories/#{name}/env" end |
Instance Attribute Details
#accessory_config ⇒ Object (readonly)
Returns the value of attribute accessory_config.
6 7 8 |
# File 'lib/kamal/configuration/accessory.rb', line 6 def accessory_config @accessory_config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/kamal/configuration/accessory.rb', line 6 def env @env end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/kamal/configuration/accessory.rb', line 6 def name @name end |
Instance Method Details
#cmd ⇒ Object
87 88 89 |
# File 'lib/kamal/configuration/accessory.rb', line 87 def cmd accessory_config["cmd"] end |
#directories ⇒ Object
64 65 66 67 68 69 |
# File 'lib/kamal/configuration/accessory.rb', line 64 def directories accessory_config["directories"]&.to_h do |host_to_container_mapping| host_path, container_path = host_to_container_mapping.split(":") [ (host_path), container_path ] end || {} end |
#env_args ⇒ Object
53 54 55 |
# File 'lib/kamal/configuration/accessory.rb', line 53 def env_args env.args end |
#files ⇒ Object
57 58 59 60 61 62 |
# File 'lib/kamal/configuration/accessory.rb', line 57 def files accessory_config["files"]&.to_h do |local_to_remote_mapping| local_file, remote_file = local_to_remote_mapping.split(":") [ (local_file), (remote_file) ] end || {} end |
#hosts ⇒ Object
31 32 33 |
# File 'lib/kamal/configuration/accessory.rb', line 31 def hosts hosts_from_host || hosts_from_hosts || hosts_from_roles end |
#image ⇒ Object
27 28 29 |
# File 'lib/kamal/configuration/accessory.rb', line 27 def image accessory_config["image"] end |
#label_args ⇒ Object
49 50 51 |
# File 'lib/kamal/configuration/accessory.rb', line 49 def label_args argumentize "--label", labels end |
#labels ⇒ Object
45 46 47 |
# File 'lib/kamal/configuration/accessory.rb', line 45 def labels default_labels.merge(accessory_config["labels"] || {}) end |
#option_args ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/kamal/configuration/accessory.rb', line 79 def option_args if args = accessory_config["options"] optionize args else [] end end |
#port ⇒ Object
35 36 37 38 39 |
# File 'lib/kamal/configuration/accessory.rb', line 35 def port if port = accessory_config["port"]&.to_s port.include?(":") ? port : "#{port}:#{port}" end end |
#publish_args ⇒ Object
41 42 43 |
# File 'lib/kamal/configuration/accessory.rb', line 41 def publish_args argumentize "--publish", port if port end |
#service_name ⇒ Object
23 24 25 |
# File 'lib/kamal/configuration/accessory.rb', line 23 def service_name accessory_config["service"] || "#{config.service}-#{name}" end |
#volume_args ⇒ Object
75 76 77 |
# File 'lib/kamal/configuration/accessory.rb', line 75 def volume_args argumentize "--volume", volumes end |
#volumes ⇒ Object
71 72 73 |
# File 'lib/kamal/configuration/accessory.rb', line 71 def volumes specific_volumes + remote_files_as_volumes + remote_directories_as_volumes end |