Class: Mrsk::Configuration
- Inherits:
-
Object
- Object
- Mrsk::Configuration
- Defined in:
- lib/mrsk/configuration.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#raw_config ⇒ Object
Returns the value of attribute raw_config.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_image ⇒ Object
- #accessories ⇒ Object
- #accessory(name) ⇒ Object
- #all_hosts ⇒ Object
- #audit_broadcast_cmd ⇒ Object
- #env_args ⇒ Object
- #healthcheck ⇒ Object
-
#initialize(raw_config, version: "missing", validate: true) ⇒ Configuration
constructor
A new instance of Configuration.
- #latest_image ⇒ Object
- #primary_web_host ⇒ Object
- #repository ⇒ Object
- #role(name) ⇒ Object
- #roles ⇒ Object
- #service_with_version ⇒ Object
- #ssh_options ⇒ Object
- #ssh_proxy ⇒ Object
- #ssh_user ⇒ Object
- #to_h ⇒ Object
- #traefik_hosts ⇒ Object
- #valid? ⇒ Boolean
- #volume_args ⇒ Object
Constructor Details
#initialize(raw_config, version: "missing", validate: true) ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 |
# File 'lib/mrsk/configuration.rb', line 40 def initialize(raw_config, version: "missing", validate: true) @raw_config = ActiveSupport::InheritableOptions.new(raw_config) @version = version valid? if validate end |
Instance Attribute Details
#raw_config ⇒ Object
Returns the value of attribute raw_config.
13 14 15 |
# File 'lib/mrsk/configuration.rb', line 13 def raw_config @raw_config end |
#version ⇒ Object
Returns the value of attribute version.
12 13 14 |
# File 'lib/mrsk/configuration.rb', line 12 def version @version end |
Class Method Details
.create_from(base_config_file, destination: nil, version: "missing") ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/mrsk/configuration.rb', line 16 def create_from(base_config_file, destination: nil, version: "missing") new(load_config_file(base_config_file).tap do |config| if destination config.deep_merge! \ load_config_file destination_config_file(base_config_file, destination) end end, version: version) end |
Instance Method Details
#absolute_image ⇒ Object
81 82 83 |
# File 'lib/mrsk/configuration.rb', line 81 def absolute_image "#{repository}:#{version}" end |
#accessories ⇒ Object
55 56 57 |
# File 'lib/mrsk/configuration.rb', line 55 def accessories @accessories ||= raw_config.accessories&.keys&.collect { |name| Mrsk::Configuration::Accessory.new(name, config: self) } || [] end |
#accessory(name) ⇒ Object
59 60 61 |
# File 'lib/mrsk/configuration.rb', line 59 def accessory(name) accessories.detect { |a| a.name == name.to_s } end |
#all_hosts ⇒ Object
64 65 66 |
# File 'lib/mrsk/configuration.rb', line 64 def all_hosts roles.flat_map(&:hosts) end |
#audit_broadcast_cmd ⇒ Object
131 132 133 |
# File 'lib/mrsk/configuration.rb', line 131 def audit_broadcast_cmd raw_config.audit_broadcast_cmd end |
#env_args ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/mrsk/configuration.rb', line 94 def env_args if raw_config.env.present? argumentize_env_with_secrets(raw_config.env) else [] end end |
#healthcheck ⇒ Object
135 136 137 |
# File 'lib/mrsk/configuration.rb', line 135 def healthcheck { "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {}) end |
#latest_image ⇒ Object
85 86 87 |
# File 'lib/mrsk/configuration.rb', line 85 def latest_image "#{repository}:latest" end |
#primary_web_host ⇒ Object
68 69 70 |
# File 'lib/mrsk/configuration.rb', line 68 def primary_web_host role(:web).hosts.first end |
#repository ⇒ Object
77 78 79 |
# File 'lib/mrsk/configuration.rb', line 77 def repository [ raw_config.registry["server"], image ].compact.join("/") end |
#role(name) ⇒ Object
51 52 53 |
# File 'lib/mrsk/configuration.rb', line 51 def role(name) roles.detect { |r| r.name == name.to_s } end |
#roles ⇒ Object
47 48 49 |
# File 'lib/mrsk/configuration.rb', line 47 def roles @roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) } end |
#service_with_version ⇒ Object
89 90 91 |
# File 'lib/mrsk/configuration.rb', line 89 def service_with_version "#{service}-#{version}" end |
#ssh_options ⇒ Object
126 127 128 |
# File 'lib/mrsk/configuration.rb', line 126 def { user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact end |
#ssh_proxy ⇒ Object
119 120 121 122 123 124 |
# File 'lib/mrsk/configuration.rb', line 119 def ssh_proxy if raw_config.ssh.present? && raw_config.ssh["proxy"] Net::SSH::Proxy::Jump.new \ raw_config.ssh["proxy"].include?("@") ? raw_config.ssh["proxy"] : "root@#{raw_config.ssh["proxy"]}" end end |
#ssh_user ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/mrsk/configuration.rb', line 111 def ssh_user if raw_config.ssh.present? raw_config.ssh["user"] || "root" else "root" end end |
#to_h ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mrsk/configuration.rb', line 145 def to_h { roles: role_names, hosts: all_hosts, primary_host: primary_web_host, version: version, repository: repository, absolute_image: absolute_image, service_with_version: service_with_version, env_args: env_args, volume_args: volume_args, ssh_options: , builder: raw_config.builder, accessories: raw_config.accessories, healthcheck: healthcheck }.compact end |
#traefik_hosts ⇒ Object
72 73 74 |
# File 'lib/mrsk/configuration.rb', line 72 def traefik_hosts roles.select(&:running_traefik?).flat_map(&:hosts) end |
#valid? ⇒ Boolean
140 141 142 |
# File 'lib/mrsk/configuration.rb', line 140 def valid? ensure_required_keys_present && ensure_env_available end |
#volume_args ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/mrsk/configuration.rb', line 102 def volume_args if raw_config.volumes.present? argumentize "--volume", raw_config.volumes else [] end end |