Class: Mrsk::Configuration
- Inherits:
-
Object
- Object
- Mrsk::Configuration
- Defined in:
- lib/mrsk/configuration.rb
Defined Under Namespace
Classes: Accessory, Boot, Builder, Role
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
- #boot ⇒ Object
- #builder ⇒ Object
-
#ensure_env_available ⇒ Object
Will raise KeyError if any secret ENVs are missing.
- #env_args ⇒ Object
- #healthcheck ⇒ Object
- #hooks_path ⇒ Object
-
#initialize(raw_config, destination: nil, version: nil, validate: true) ⇒ Configuration
constructor
A new instance of Configuration.
- #latest_image ⇒ Object
- #logging_args ⇒ Object
- #minimum_version ⇒ 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
99 100 101 |
# File 'lib/mrsk/configuration.rb', line 99 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 |
#boot ⇒ Object
90 91 92 |
# File 'lib/mrsk/configuration.rb', line 90 def boot Mrsk::Configuration::Boot.new(config: self) end |
#builder ⇒ Object
204 205 206 |
# File 'lib/mrsk/configuration.rb', line 204 def builder Mrsk::Configuration::Builder.new(config: self) end |
#ensure_env_available ⇒ Object
Will raise KeyError if any secret ENVs are missing
209 210 211 212 213 214 |
# File 'lib/mrsk/configuration.rb', line 209 def ensure_env_available env_args roles.each(&:env_args) true end |
#env_args ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/mrsk/configuration.rb', line 112 def env_args if raw_config.env.present? argumentize_env_with_secrets(raw_config.env) else [] end end |
#healthcheck ⇒ Object
160 161 162 |
# File 'lib/mrsk/configuration.rb', line 160 def healthcheck { "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {}) end |
#hooks_path ⇒ Object
200 201 202 |
# File 'lib/mrsk/configuration.rb', line 200 def hooks_path raw_config.hooks_path || ".mrsk/hooks" end |
#latest_image ⇒ Object
103 104 105 |
# File 'lib/mrsk/configuration.rb', line 103 def latest_image "#{repository}:latest" end |
#logging_args ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/mrsk/configuration.rb', line 128 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 |
#minimum_version ⇒ Object
168 169 170 |
# File 'lib/mrsk/configuration.rb', line 168 def minimum_version raw_config.minimum_version 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
164 165 166 |
# File 'lib/mrsk/configuration.rb', line 164 def readiness_delay raw_config.readiness_delay || 7 end |
#repository ⇒ Object
95 96 97 |
# File 'lib/mrsk/configuration.rb', line 95 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
107 108 109 |
# File 'lib/mrsk/configuration.rb', line 107 def service_with_version "#{service}-#{version}" end |
#ssh_options ⇒ Object
155 156 157 |
# File 'lib/mrsk/configuration.rb', line 155 def { user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact end |
#ssh_proxy ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/mrsk/configuration.rb', line 146 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"]}" elsif raw_config.ssh.present? && raw_config.ssh["proxy_command"] Net::SSH::Proxy::Command.new(raw_config.ssh["proxy_command"]) end end |
#ssh_user ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/mrsk/configuration.rb', line 138 def ssh_user if raw_config.ssh.present? raw_config.ssh["user"] || "root" else "root" end end |
#to_h ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mrsk/configuration.rb', line 177 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: builder.to_h, accessories: raw_config.accessories, logging: logging_args, healthcheck: healthcheck }.compact end |
#traefik ⇒ Object
196 197 198 |
# File 'lib/mrsk/configuration.rb', line 196 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
172 173 174 |
# File 'lib/mrsk/configuration.rb', line 172 def valid? ensure_required_keys_present && ensure_valid_mrsk_version end |
#version ⇒ Object
52 53 54 |
# File 'lib/mrsk/configuration.rb', line 52 def version @declared_version.presence || ENV["VERSION"] || git_version end |
#version=(version) ⇒ Object
48 49 50 |
# File 'lib/mrsk/configuration.rb', line 48 def version=(version) @declared_version = version end |
#volume_args ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/mrsk/configuration.rb', line 120 def volume_args if raw_config.volumes.present? argumentize "--volume", raw_config.volumes else [] end end |