class Dapp::Kube::Helm::Values
Constants
- TEMPLATE_EMPTY_VALUE
Attributes
data[R]
Public Class Methods
new(data={})
click to toggle source
# File lib/dapp/kube/helm/values.rb, line 117 def initialize(data={}) @data = data end
service_values(*a, &b)
click to toggle source
# File lib/dapp/kube/helm/values.rb, line 7 def service_values(*a, &b) self.new(service_values_hash(*a, &b)) end
service_values_hash(dapp, repo, namespace, docker_tag, fake: false, without_registry: false, disable_warnings: false)
click to toggle source
# File lib/dapp/kube/helm/values.rb, line 11 def service_values_hash(dapp, repo, namespace, docker_tag, fake: false, without_registry: false, disable_warnings: false) res = { "global" => { "namespace" => namespace, "dapp" => { "name" => dapp.name, "repo" => repo, "docker_tag" => docker_tag, }, # TODO: enable again with chars escape # "ci" => ENV.select { |k, _| k.start_with?('CI_') && k != "CI_ENVIRONMENT_URL" }, } } ci_info = { "is_tag" => false, "is_branch" => false, "branch" => TEMPLATE_EMPTY_VALUE, "tag" => TEMPLATE_EMPTY_VALUE, "ref" => TEMPLATE_EMPTY_VALUE } res["global"]["dapp"]["ci"] = ci_info if fake elsif commit_tag = (ENV["CI_BUILD_TAG"] || ENV["CI_COMMIT_TAG"]) ci_info["tag"] = ci_info["ref"] = commit_tag ci_info["is_tag"] = true elsif commit_ref_name = (ENV["CI_BUILD_REF_NAME"] || ENV["CI_COMMIT_REF_NAME"]) ci_info["branch"] = ci_info["ref"] = commit_ref_name ci_info["is_branch"] = true elsif dapp.git_own_repo_exist? and dapp.git_own_repo.head_branch_name != "HEAD" ci_info["branch"] = ci_info["ref"] = dapp.git_own_repo.head_branch_name ci_info["is_branch"] = true elsif dapp.git_own_repo_exist? git = dapp.git_own_repo.send(:git) tagref = git.references.find do |r| if r.name.start_with?("refs/tags/") if r.target.is_a? Rugged::Tag::Annotation r.target.target_id == git.head.target_id else r.target_id == git.head.target_id end end end if tagref tag = tagref.name.partition("refs/tags/").last else tag = git.head.target_id end ci_info["tag"] = ci_info["ref"] = tag ci_info["is_tag"] = true end dimgs = dapp.build_configs.map do |config| dapp.dimg(config: config, ignore_signature_auto_calculation: true) end.uniq do |dimg| dimg.name end dimgs.each do |dimg| dimg_data = {} if dimg.name res["global"]["dapp"]["is_nameless_dimg"] = false res["global"]["dapp"]["dimg"] ||= {} res["global"]["dapp"]["dimg"][dimg.name] = dimg_data else res["global"]["dapp"]["is_nameless_dimg"] = true res["global"]["dapp"]["dimg"] = dimg_data end dimg_labels = {} docker_image_id = TEMPLATE_EMPTY_VALUE unless fake || without_registry begin dimg_labels = dapp.dimg_registry(repo).image_config(docker_tag, dimg.name)["config"]["Labels"] docker_image_id = dapp.dimg_registry(repo).image_id(docker_tag, dimg.name) rescue ::Dapp::Dimg::Error::Registry => e unless disable_warnings dapp.log_warning "Cannot determine <dimg>.docker_image_id and <dimg>.git.<ga>.commit_id helm values of dimg#{dimg.name ? " `#{dimg.name}`" : nil}: #{e.net_status[:data][:message]}" end end end dimg_data["docker_image"] = [[repo, dimg.name].compact.join("/"), docker_tag].join(":") dimg_data["docker_image_id"] = docker_image_id dimg.git_artifacts(omit_empty: false).each do |ga| if ga.as commit_id = dimg_labels[dapp.dimgstage_g_a_commit_label(ga.paramshash)] || TEMPLATE_EMPTY_VALUE dimg_data["git"] ||= {} dimg_data["git"][ga.as] ||= {} dimg_data["git"][ga.as]["commit_id"] = commit_id end end end res end
Public Instance Methods
as_set_options()
click to toggle source
# File lib/dapp/kube/helm/values.rb, line 121 def as_set_options options = {} queue = [[nil, data]] loop do option_key, hash = queue.shift break unless hash hash.each do |k, v| new_option_key = [option_key, k].compact.join(".") if v.is_a? Hash queue << [new_option_key, v] else options[new_option_key] = v end end end options end
to_set_options()
click to toggle source
# File lib/dapp/kube/helm/values.rb, line 143 def to_set_options as_set_options.map {|k, v| "--set '#{k}=#{v}'"} end