11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# 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,
},
}
}
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 ENV["CI_COMMIT_TAG"]
ci_info["tag"] = ci_info["ref"] = ENV["CI_COMMIT_TAG"]
ci_info["is_tag"] = true
elsif ENV["CI_COMMIT_REF_NAME"]
ci_info["branch"] = ci_info["ref"] = ENV["CI_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
|