Class: Mrsk::Configuration
- Inherits:
-
Object
- Object
- Mrsk::Configuration
- Defined in:
- lib/mrsk/configuration.rb
Defined Under Namespace
Classes: Role
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_image ⇒ Object
- #env_args ⇒ Object
- #hosts ⇒ Object
-
#initialize(config, validate: true) ⇒ Configuration
constructor
A new instance of Configuration.
- #master_key ⇒ Object
- #primary_host ⇒ Object
- #repository ⇒ Object
- #role(name) ⇒ Object
- #roles ⇒ Object
- #service_with_version ⇒ Object
- #ssh_options ⇒ Object
- #ssh_user ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(config, validate: true) ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 |
# File 'lib/mrsk/configuration.rb', line 24 def initialize(config, validate: true) @config = ActiveSupport::InheritableOptions.new(config) ensure_required_keys_present if validate end |
Class Method Details
.argumentize(argument, attributes) ⇒ Object
19 20 21 |
# File 'lib/mrsk/configuration.rb', line 19 def argumentize(argument, attributes) attributes.flat_map { |k, v| [ argument, "#{k}=#{v}" ] } end |
.load_file(file) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mrsk/configuration.rb', line 11 def load_file(file) if file.exist? new YAML.load(ERB.new(IO.read(file)).result).symbolize_keys else raise "Configuration file not found in #{file}" end end |
Instance Method Details
#absolute_image ⇒ Object
70 71 72 |
# File 'lib/mrsk/configuration.rb', line 70 def absolute_image "#{repository}:#{version}" end |
#env_args ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/mrsk/configuration.rb', line 79 def env_args if config.env.present? self.class.argumentize "-e", config.env else [] end end |
#hosts ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mrsk/configuration.rb', line 38 def hosts hosts = case when ENV["HOSTS"] ENV["HOSTS"].split(",") when ENV["ROLES"] role_names = ENV["ROLES"].split(",") roles.select { |r| role_names.include?(r.name) }.flat_map(&:hosts) else roles.flat_map(&:hosts) end if hosts.any? hosts else raise ArgumentError, "No hosts found" end end |
#master_key ⇒ Object
95 96 97 |
# File 'lib/mrsk/configuration.rb', line 95 def master_key ENV["RAILS_MASTER_KEY"] || File.read(Pathname.new(File.("config/master.key"))) end |
#primary_host ⇒ Object
57 58 59 |
# File 'lib/mrsk/configuration.rb', line 57 def primary_host role(:web).hosts.first end |
#repository ⇒ Object
66 67 68 |
# File 'lib/mrsk/configuration.rb', line 66 def repository [ config.registry["server"], image ].compact.join("/") end |
#role(name) ⇒ Object
34 35 36 |
# File 'lib/mrsk/configuration.rb', line 34 def role(name) roles.detect { |r| r.name == name.to_s } end |
#roles ⇒ Object
30 31 32 |
# File 'lib/mrsk/configuration.rb', line 30 def roles @roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) } end |
#service_with_version ⇒ Object
74 75 76 |
# File 'lib/mrsk/configuration.rb', line 74 def service_with_version "#{service}-#{version}" end |
#ssh_options ⇒ Object
91 92 93 |
# File 'lib/mrsk/configuration.rb', line 91 def { user: ssh_user, auth_methods: [ "publickey" ] } end |
#ssh_user ⇒ Object
87 88 89 |
# File 'lib/mrsk/configuration.rb', line 87 def ssh_user config.ssh_user || "root" end |
#version ⇒ Object
62 63 64 |
# File 'lib/mrsk/configuration.rb', line 62 def version @version ||= ENV["VERSION"] || `git rev-parse HEAD`.strip end |