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.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_image ⇒ Object
- #accessories ⇒ Object
- #accessory(name) ⇒ Object
- #all_hosts ⇒ Object
- #env_args ⇒ Object
-
#initialize(raw_config, version: "missing", validate: true) ⇒ Configuration
constructor
A new instance of Configuration.
- #master_key ⇒ Object
- #primary_web_host ⇒ Object
- #repository ⇒ Object
- #role(name) ⇒ Object
- #roles ⇒ Object
- #service_with_version ⇒ Object
- #ssh_options ⇒ Object
- #ssh_user ⇒ Object
- #to_h ⇒ Object
- #traefik_hosts ⇒ Object
- #version ⇒ Object
- #volume_args ⇒ Object
Constructor Details
#initialize(raw_config, version: "missing", validate: true) ⇒ Configuration
Returns a new instance of Configuration.
39 40 41 42 43 |
# File 'lib/mrsk/configuration.rb', line 39 def initialize(raw_config, version: "missing", validate: true) @raw_config = ActiveSupport::InheritableOptions.new(raw_config) @version = version ensure_required_keys_present if validate end |
Instance Attribute Details
#raw_config ⇒ Object
Returns the value of attribute raw_config.
12 13 14 |
# File 'lib/mrsk/configuration.rb', line 12 def raw_config @raw_config end |
Class Method Details
.create_from(base_config_file, destination: nil, version: "missing") ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/mrsk/configuration.rb', line 15 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
84 85 86 |
# File 'lib/mrsk/configuration.rb', line 84 def absolute_image "#{repository}:#{version}" end |
#accessories ⇒ Object
54 55 56 |
# File 'lib/mrsk/configuration.rb', line 54 def accessories @accessories ||= raw_config.accessories&.keys&.collect { |name| Mrsk::Configuration::Assessory.new(name, config: self) } || [] end |
#accessory(name) ⇒ Object
58 59 60 |
# File 'lib/mrsk/configuration.rb', line 58 def accessory(name) accessories.detect { |a| a.name == name.to_s } end |
#all_hosts ⇒ Object
63 64 65 |
# File 'lib/mrsk/configuration.rb', line 63 def all_hosts roles.flat_map(&:hosts) end |
#env_args ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/mrsk/configuration.rb', line 93 def env_args if raw_config.env.present? argumentize_env_with_secrets(raw_config.env) else [] end end |
#master_key ⇒ Object
117 118 119 120 121 |
# File 'lib/mrsk/configuration.rb', line 117 def master_key unless raw_config.skip_master_key ENV["RAILS_MASTER_KEY"] || File.read(Pathname.new(File.("config/master.key"))) end end |
#primary_web_host ⇒ Object
67 68 69 |
# File 'lib/mrsk/configuration.rb', line 67 def primary_web_host role(:web).hosts.first end |
#repository ⇒ Object
80 81 82 |
# File 'lib/mrsk/configuration.rb', line 80 def repository [ raw_config.registry["server"], image ].compact.join("/") end |
#role(name) ⇒ Object
50 51 52 |
# File 'lib/mrsk/configuration.rb', line 50 def role(name) roles.detect { |r| r.name == name.to_s } end |
#roles ⇒ Object
46 47 48 |
# File 'lib/mrsk/configuration.rb', line 46 def roles @roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) } end |
#service_with_version ⇒ Object
88 89 90 |
# File 'lib/mrsk/configuration.rb', line 88 def service_with_version "#{service}-#{version}" end |
#ssh_options ⇒ Object
113 114 115 |
# File 'lib/mrsk/configuration.rb', line 113 def { user: ssh_user, auth_methods: [ "publickey" ] } end |
#ssh_user ⇒ Object
109 110 111 |
# File 'lib/mrsk/configuration.rb', line 109 def ssh_user raw_config.ssh_user || "root" end |
#to_h ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mrsk/configuration.rb', line 123 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 }.compact end |
#traefik_hosts ⇒ Object
71 72 73 |
# File 'lib/mrsk/configuration.rb', line 71 def traefik_hosts roles.select(&:running_traefik?).flat_map(&:hosts) end |
#version ⇒ Object
76 77 78 |
# File 'lib/mrsk/configuration.rb', line 76 def version @version end |
#volume_args ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/mrsk/configuration.rb', line 101 def volume_args if raw_config.volumes.present? argumentize "--volume", raw_config.volumes else [] end end |