Class: Vidar::Config
- Inherits:
-
Object
- Object
- Vidar::Config
- Defined in:
- lib/vidar/config.rb
Constant Summary collapse
- DEFAULT_MANIFEST_FILE =
"vidar.yml".freeze
- DEFAULT_BRANCHES =
%w[main master].freeze
- DEFAULT_OPTIONS =
{ compose_file: -> { "docker-compose.ci.yml" }, compose_cmd: -> { "docker compose" }, default_branch: -> { (DEFAULT_BRANCHES & branches).first || DEFAULT_BRANCHES.first }, current_branch: -> { (ENV['SEMAPHORE_GIT_WORKING_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.strip).tr("/", "-") }, revision: -> { `git rev-parse HEAD`.strip }, revision_name: -> { `git show --pretty=format:"%s (%h)" -s HEAD`.strip }, kubectl_context: -> { `kubectl config current-context`.strip }, shell_command: -> { "/bin/sh" }, console_command: -> { "bin/console" }, base_stage_name: -> { "base" }, release_stage_name: -> { "release" }, honeycomb_api_key: -> { ENV['HONEYCOMB_API_KEY'] }, }.freeze
Class Attribute Summary collapse
-
.data ⇒ Object
readonly
Returns the value of attribute data.
- .manifest_file ⇒ Object
Class Method Summary collapse
- .branches ⇒ Object
- .build_deploy_config(kubectl_context) ⇒ Object
- .build_url ⇒ Object
- .default_branch? ⇒ Boolean
- .deploy_config ⇒ Object
- .deploy_configs ⇒ Object
- .ensure_file_exist!(file_path) ⇒ Object
- .get(key) ⇒ Object
- .get!(key) ⇒ Object
- .honeycomb_env_api_key(env) ⇒ Object
- .load(file_path = manifest_file) ⇒ Object
- .loaded? ⇒ Boolean
Class Attribute Details
.data ⇒ Object (readonly)
Returns the value of attribute data.
22 23 24 |
# File 'lib/vidar/config.rb', line 22 def data @data end |
.manifest_file ⇒ Object
32 33 34 |
# File 'lib/vidar/config.rb', line 32 def manifest_file @manifest_file || DEFAULT_MANIFEST_FILE end |
Class Method Details
.branches ⇒ Object
91 92 93 |
# File 'lib/vidar/config.rb', line 91 def branches `git for-each-ref --format='%(refname:short)' refs/heads/*`.split("\n") end |
.build_deploy_config(kubectl_context) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vidar/config.rb', line 71 def build_deploy_config(kubectl_context) deployments = get(:deployments) deployments = {} unless deployments.is_a?(Hash) deployment = deployments[kubectl_context] if deployment.nil? Log.error "ERROR: could not find deployment config for #{get!(:kubectl_context)} context" return nil end deployment.transform_keys!(&:to_sym) deployment.transform_values! { |value| Vidar::Interpolation.call(value, self) } DeployConfig.new(deployment) end |
.build_url ⇒ Object
58 59 60 61 |
# File 'lib/vidar/config.rb', line 58 def build_url value = ENV[get(:build_env).to_s] || get(:build_url) value&.empty? ? nil : value end |
.default_branch? ⇒ Boolean
95 96 97 |
# File 'lib/vidar/config.rb', line 95 def default_branch? get!(:current_branch) == get!(:default_branch) end |
.deploy_config ⇒ Object
67 68 69 |
# File 'lib/vidar/config.rb', line 67 def deploy_config deploy_configs[get!(:kubectl_context)] ||= build_deploy_config(get!(:kubectl_context)) end |
.deploy_configs ⇒ Object
87 88 89 |
# File 'lib/vidar/config.rb', line 87 def deploy_configs @deploy_configs ||= {} end |
.ensure_file_exist!(file_path) ⇒ Object
36 37 38 |
# File 'lib/vidar/config.rb', line 36 def ensure_file_exist!(file_path) fail(MissingManifestFileError, file_path) unless File.exist?(file_path) end |
.get(key) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/vidar/config.rb', line 44 def get(key) load unless loaded? value = @data[key.to_s] || DEFAULT_OPTIONS[key.to_sym]&.call return value unless value.is_a?(String) Vidar::Interpolation.call(value, self) end |
.get!(key) ⇒ Object
54 55 56 |
# File 'lib/vidar/config.rb', line 54 def get!(key) get(key) || fail(MissingConfigError, key) end |
.honeycomb_env_api_key(env) ⇒ Object
63 64 65 |
# File 'lib/vidar/config.rb', line 63 def honeycomb_env_api_key(env) ENV["HONEYCOMB_API_KEY_#{env.upcase}"] end |
.load(file_path = manifest_file) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/vidar/config.rb', line 25 def load(file_path = manifest_file) ensure_file_exist!(file_path) @data = YAML.load_file(file_path) @loaded = true end |
.loaded? ⇒ Boolean
40 41 42 |
# File 'lib/vidar/config.rb', line 40 def loaded? @loaded end |