Class: Mrsk::Configuration
- Inherits:
-
Object
- Object
- Mrsk::Configuration
- Defined in:
- lib/mrsk/configuration.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#raw_config ⇒ Object
Returns the value of attribute raw_config.
Class Method Summary collapse
Instance Method Summary collapse
- #abbreviated_version ⇒ Object
- #absolute_image ⇒ Object
- #accessories ⇒ Object
- #accessory(name) ⇒ Object
- #all_hosts ⇒ Object
- #audit_broadcast_cmd ⇒ Object
- #env_args ⇒ Object
- #healthcheck ⇒ Object
-
#initialize(raw_config, destination: nil, version: nil, validate: true) ⇒ Configuration
constructor
A new instance of Configuration.
- #latest_image ⇒ Object
- #logging_args ⇒ Object
- #primary_web_host ⇒ Object
- #readiness_delay ⇒ 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 ⇒ Object
- #traefik_hosts ⇒ Object
- #valid? ⇒ Boolean
- #version ⇒ Object
- #version=(version) ⇒ Object
- #volume_args ⇒ Object
Constructor Details
#initialize(raw_config, destination: nil, version: nil, validate: true) ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 45 |
# File 'lib/mrsk/configuration.rb', line 40 def initialize(raw_config, destination: nil, version: nil, validate: true) @raw_config = ActiveSupport::InheritableOptions.new(raw_config) @destination = destination @declared_version = version valid? if validate end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
12 13 14 |
# File 'lib/mrsk/configuration.rb', line 12 def destination @destination end |
#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 |
Class Method Details
.create_from(config_file:, destination: nil, version: nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/mrsk/configuration.rb', line 16 def create_from(config_file:, destination: nil, version: nil) raw_config = load_config_files(config_file, *destination_config_file(config_file, destination)) new raw_config, destination: destination, version: version end |
Instance Method Details
#abbreviated_version ⇒ Object
56 57 58 |
# File 'lib/mrsk/configuration.rb', line 56 def abbreviated_version Mrsk::Utils.abbreviate_version(version) end |
#absolute_image ⇒ Object
95 96 97 |
# File 'lib/mrsk/configuration.rb', line 95 def absolute_image "#{repository}:#{version}" end |
#accessories ⇒ Object
69 70 71 |
# File 'lib/mrsk/configuration.rb', line 69 def accessories @accessories ||= raw_config.accessories&.keys&.collect { |name| Mrsk::Configuration::Accessory.new(name, config: self) } || [] end |
#accessory(name) ⇒ Object
73 74 75 |
# File 'lib/mrsk/configuration.rb', line 73 def accessory(name) accessories.detect { |a| a.name == name.to_s } end |
#all_hosts ⇒ Object
78 79 80 |
# File 'lib/mrsk/configuration.rb', line 78 def all_hosts roles.flat_map(&:hosts).uniq end |
#audit_broadcast_cmd ⇒ Object
154 155 156 |
# File 'lib/mrsk/configuration.rb', line 154 def audit_broadcast_cmd raw_config.audit_broadcast_cmd end |
#env_args ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/mrsk/configuration.rb', line 108 def env_args if raw_config.env.present? argumentize_env_with_secrets(raw_config.env) else [] end end |
#healthcheck ⇒ Object
158 159 160 |
# File 'lib/mrsk/configuration.rb', line 158 def healthcheck { "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {}) end |
#latest_image ⇒ Object
99 100 101 |
# File 'lib/mrsk/configuration.rb', line 99 def latest_image "#{repository}:latest" end |
#logging_args ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/mrsk/configuration.rb', line 124 def logging_args if raw_config.logging.present? optionize({ "log-driver" => raw_config.logging["driver"] }.compact) + argumentize("--log-opt", raw_config.logging["options"]) else argumentize("--log-opt", { "max-size" => "10m" }) end end |
#primary_web_host ⇒ Object
82 83 84 |
# File 'lib/mrsk/configuration.rb', line 82 def primary_web_host role(:web).primary_host end |
#readiness_delay ⇒ Object
162 163 164 |
# File 'lib/mrsk/configuration.rb', line 162 def readiness_delay raw_config.readiness_delay || 7 end |
#repository ⇒ Object
91 92 93 |
# File 'lib/mrsk/configuration.rb', line 91 def repository [ raw_config.registry["server"], image ].compact.join("/") end |
#role(name) ⇒ Object
65 66 67 |
# File 'lib/mrsk/configuration.rb', line 65 def role(name) roles.detect { |r| r.name == name.to_s } end |
#roles ⇒ Object
61 62 63 |
# File 'lib/mrsk/configuration.rb', line 61 def roles @roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) } end |
#service_with_version ⇒ Object
103 104 105 |
# File 'lib/mrsk/configuration.rb', line 103 def service_with_version "#{service}-#{version}" end |
#ssh_options ⇒ Object
149 150 151 |
# File 'lib/mrsk/configuration.rb', line 149 def { user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact end |
#ssh_proxy ⇒ Object
142 143 144 145 146 147 |
# File 'lib/mrsk/configuration.rb', line 142 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
134 135 136 137 138 139 140 |
# File 'lib/mrsk/configuration.rb', line 134 def ssh_user if raw_config.ssh.present? raw_config.ssh["user"] || "root" else "root" end end |
#to_h ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/mrsk/configuration.rb', line 171 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, logging: logging_args, healthcheck: healthcheck }.compact end |
#traefik ⇒ Object
190 191 192 |
# File 'lib/mrsk/configuration.rb', line 190 def traefik raw_config.traefik || {} end |
#traefik_hosts ⇒ Object
86 87 88 |
# File 'lib/mrsk/configuration.rb', line 86 def traefik_hosts roles.select(&:running_traefik?).flat_map(&:hosts).uniq end |
#valid? ⇒ Boolean
166 167 168 |
# File 'lib/mrsk/configuration.rb', line 166 def valid? ensure_required_keys_present && ensure_env_available end |
#version ⇒ Object
52 53 54 |
# File 'lib/mrsk/configuration.rb', line 52 def version @declared_version.presence || ENV["VERSION"] || current_commit_hash end |
#version=(version) ⇒ Object
48 49 50 |
# File 'lib/mrsk/configuration.rb', line 48 def version=(version) @declared_version = version end |
#volume_args ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/mrsk/configuration.rb', line 116 def volume_args if raw_config.volumes.present? argumentize "--volume", raw_config.volumes else [] end end |