dapp 0.21.16 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/bin/dapp +0 -4
  3. data/config/en/net_status.yml +3 -2
  4. data/lib/dapp.rb +1 -4
  5. data/lib/dapp/cli.rb +0 -4
  6. data/lib/dapp/cli/command/base.rb +1 -7
  7. data/lib/dapp/cli/command/update.rb +1 -1
  8. data/lib/dapp/dapp.rb +19 -40
  9. data/lib/dapp/dapp/command/common.rb +19 -0
  10. data/lib/dapp/dapp/option_tags.rb +4 -6
  11. data/lib/dapp/dimg/build/stage/artifact_default.rb +1 -1
  12. data/lib/dapp/dimg/builder/chef/cookbook.rb +1 -1
  13. data/lib/dapp/dimg/cli/command/base.rb +4 -0
  14. data/lib/dapp/dimg/config/directive/artifact_dimg.rb +7 -0
  15. data/lib/dapp/dimg/config/directive/dimg/instance_methods.rb +0 -1
  16. data/lib/dapp/dimg/config/directive/dimg/validation.rb +16 -39
  17. data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +7 -6
  18. data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +98 -24
  19. data/lib/dapp/dimg/dapp/command/common.rb +4 -13
  20. data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +9 -7
  21. data/lib/dapp/dimg/dapp/command/stages/cleanup_repo.rb +1 -1
  22. data/lib/dapp/dimg/dapp/command/stages/common.rb +1 -6
  23. data/lib/dapp/dimg/dapp/command/stages/flush_local.rb +5 -3
  24. data/lib/dapp/dimg/dapp/command/stages/flush_repo.rb +1 -1
  25. data/lib/dapp/dimg/docker_registry/dimg.rb +0 -9
  26. data/lib/dapp/dimg/git_repo/base.rb +30 -4
  27. data/lib/dapp/dimg/image/argument.rb +1 -3
  28. data/lib/dapp/helper/trivia.rb +0 -35
  29. data/lib/dapp/kube/cli/command/kube/deploy.rb +6 -0
  30. data/lib/dapp/kube/dapp/command/common.rb +129 -13
  31. data/lib/dapp/kube/dapp/command/deploy.rb +2 -9
  32. data/lib/dapp/kube/dapp/command/render.rb +2 -2
  33. data/lib/dapp/kube/error/base.rb +5 -1
  34. data/lib/dapp/kube/helm/release.rb +39 -3
  35. data/lib/dapp/kube/kubernetes/client.rb +2 -0
  36. data/lib/dapp/version.rb +2 -2
  37. metadata +4 -33
  38. data/lib/dapp/dapp/sentry.rb +0 -112
  39. data/lib/dapp/helper/url.rb +0 -23
@@ -3,23 +3,17 @@ module Dapp
3
3
  module Dapp
4
4
  module Command
5
5
  module CleanupRepo
6
+ DATE_POLICY = Time.now.to_i - 60 * 60 * 24 * 30
7
+ GIT_TAGS_LIMIT_POLICY = 10
8
+
6
9
  def cleanup_repo
7
10
  lock_repo(repo = option_repo) do
8
11
  registry = registry(repo)
9
12
 
10
- repo_detailed_dimgs_images(registry).select do |image|
11
- case image[:labels]['dapp-tag-scheme']
12
- when 'git_tag', 'git_branch', 'git_commit' then true
13
- else false
14
- end && !deployed_docker_images.include?([image[:dimg], image[:tag]].join(':'))
15
- end.tap do |dimgs_images|
16
- cleanup_repo_by_nonexistent_git_tag(registry, dimgs_images)
17
- cleanup_repo_by_nonexistent_git_branch(registry, dimgs_images)
18
- cleanup_repo_by_nonexistent_git_commit(registry, dimgs_images)
19
- end
13
+ cleanup_repo_by_nonexistent_git_primitive(registry, actual_detailed_dimgs_images_by_scheme(registry))
14
+ cleanup_repo_by_policies(registry, actual_detailed_dimgs_images_by_scheme(registry))
20
15
 
21
16
  begin
22
- registry.reset_cache
23
17
  repo_dimgs = repo_dimgs_images(registry)
24
18
  repo_dimgstages = repo_dimgstages_images(registry)
25
19
  repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages)
@@ -27,32 +21,83 @@ module Dapp
27
21
  end
28
22
  end
29
23
 
30
- def cleanup_repo_by_nonexistent_git_tag(registry, dimgs_images)
31
- cleanup_repo_by_nonexistent_git_base(dimgs_images, 'git_tag') do |dimg_image|
32
- delete_repo_image(registry, dimg_image) unless git_local_repo.tags.include?(dimg_image[:tag])
24
+ def actual_detailed_dimgs_images_by_scheme(registry)
25
+ {}.tap do |detailed_dimgs_images_by_scheme|
26
+ tagging_schemes.each { |scheme| detailed_dimgs_images_by_scheme[scheme] = [] }
27
+ repo_detailed_dimgs_images(registry).each do |image|
28
+ next unless repo_dimg_image_should_be_ignored?(image)
29
+ (detailed_dimgs_images_by_scheme[image[:labels]['dapp-tag-scheme']] ||= []) << image
30
+ end
33
31
  end
34
32
  end
35
33
 
36
- def cleanup_repo_by_nonexistent_git_branch(registry, dimgs_images)
37
- cleanup_repo_by_nonexistent_git_base(dimgs_images, 'git_branch') do |dimg_image|
38
- delete_repo_image(registry, dimg_image) unless git_local_repo.remote_branches.include?(dimg_image[:tag])
39
- end
34
+ def repo_dimg_image_should_be_ignored?(image)
35
+ image_repository = [option_repo, image[:dimg]].compact.join('/')
36
+ image_name = [image_repository, image[:tag]].join(':')
37
+ !deployed_docker_images.include?(image_name)
40
38
  end
41
39
 
42
- def cleanup_repo_by_nonexistent_git_commit(registry, dimgs_images)
43
- cleanup_repo_by_nonexistent_git_base(dimgs_images, 'git_commit') do |dimg_image|
44
- delete_repo_image(registry, dimg_image) unless git_local_repo.commit_exists?(dimg_image[:tag])
40
+ def cleanup_repo_by_nonexistent_git_primitive(registry, detailed_dimgs_images_by_scheme)
41
+ %w(git_tag git_branch git_commit).each do |scheme|
42
+ cleanup_repo_by_nonexistent_git_base(detailed_dimgs_images_by_scheme, scheme) do |detailed_dimg_image|
43
+ delete_repo_image(registry, detailed_dimg_image) unless begin
44
+ case scheme
45
+ when 'git_tag' then git_local_repo.tags.include?(detailed_dimg_image[:tag])
46
+ when 'git_branch' then git_local_repo.remote_branches.include?(detailed_dimg_image[:tag])
47
+ when 'git_commit' then git_local_repo.commit_exists?(detailed_dimg_image[:tag])
48
+ else
49
+ raise
50
+ end
51
+ end
52
+ end unless detailed_dimgs_images_by_scheme[scheme].empty?
45
53
  end
46
54
  end
47
55
 
48
- def cleanup_repo_by_nonexistent_git_base(dimgs_images, dapp_tag_scheme)
56
+ def cleanup_repo_by_nonexistent_git_base(repo_dimgs_images_by_scheme, dapp_tag_scheme)
57
+ return if repo_dimgs_images_by_scheme[dapp_tag_scheme].empty?
49
58
  log_step_with_indent(:"nonexistent #{dapp_tag_scheme.split('_').join(' ')}") do
50
- dimgs_images
59
+ repo_dimgs_images_by_scheme[dapp_tag_scheme]
51
60
  .select { |dimg_image| dimg_image[:labels]['dapp-tag-scheme'] == dapp_tag_scheme }
52
61
  .each { |dimg_image| yield dimg_image }
53
62
  end
54
63
  end
55
64
 
65
+ def cleanup_repo_by_policies(registry, detailed_dimgs_images_by_scheme)
66
+ %w(git_tag git_commit).each_with_object([]) do |scheme, dimgs_images|
67
+ dimgs_images.concat begin
68
+ detailed_dimgs_images_by_scheme[scheme].map do |dimg|
69
+ dimg[:created_at] = begin
70
+ if scheme == 'git_tag'
71
+ git_local_repo.tag_at(dimg[:tag])
72
+ elsif scheme == 'git_commit'
73
+ git_local_repo.commit_at(dimg[:tag])
74
+ end
75
+ end
76
+ dimg
77
+ end
78
+ end
79
+ end
80
+ .sort_by { |dimg| dimg[:created_at] }
81
+ .tap do |sorted_dimgs_images|
82
+ expired_dimgs_images, not_expired_dimgs_images = sorted_dimgs_images.partition do |dimg_image|
83
+ dimg_image[:created_at] < DATE_POLICY
84
+ end
85
+
86
+ log_step_with_indent(:"date policy (before #{DateTime.strptime(DATE_POLICY.to_s, '%s')})") do
87
+ expired_dimgs_images.each { |dimg| delete_repo_image(registry, dimg) }
88
+ end
89
+
90
+ {}.tap do |images_by_dimg|
91
+ not_expired_dimgs_images.each { |dimg| (images_by_dimg[dimg[:dimg]] ||= []) << dimg }
92
+ images_by_dimg.each do |dimg, images|
93
+ log_step_with_indent(:"limit policy (> #{GIT_TAGS_LIMIT_POLICY}) (`#{dimg}`)") do
94
+ images[GIT_TAGS_LIMIT_POLICY..-1].each { |dimg| delete_repo_image(registry, dimg) }
95
+ end unless images[GIT_TAGS_LIMIT_POLICY..-1].nil?
96
+ end
97
+ end
98
+ end
99
+ end
100
+
56
101
  def repo_detailed_dimgs_images(registry)
57
102
  repo_dimgs_images(registry).each do |dimg|
58
103
  image_history = registry.image_history(dimg[:tag], dimg[:dimg])
@@ -62,7 +107,36 @@ module Dapp
62
107
  end
63
108
 
64
109
  def deployed_docker_images
65
- []
110
+ # open kube client, get all pods and select containers' images
111
+ ::Dapp::Kube::Kubernetes::Client.tap do |kube|
112
+ config_file = kube.kube_config_path
113
+ unless File.exist?(config_file)
114
+ return []
115
+ end
116
+ end
117
+
118
+ client = ::Dapp::Kube::Kubernetes::Client.new
119
+
120
+ namespaces = []
121
+ # check connectivity for 2 seconds
122
+ begin
123
+ namespaces = client.namespace_list(excon_parameters: {:connect_timeout => 30})
124
+ rescue Excon::Error::Timeout
125
+ raise Kube::Error::Base, code: :connect_timeout
126
+ end
127
+
128
+ # get images from containers from pods from all namespaces.
129
+ @kube_images ||= namespaces['items'].map do |item|
130
+ item['metadata']['name']
131
+ end.map do |ns|
132
+ client.with_namespace(ns) do
133
+ client.pod_list['items'].map do |pod|
134
+ pod['spec']['containers'].map{ |cont| cont['image'] }
135
+ end
136
+ end
137
+ end.flatten.uniq.select do |image|
138
+ image.start_with?(option_repo)
139
+ end
66
140
  end
67
141
  end
68
142
  end
@@ -95,8 +95,10 @@ module Dapp
95
95
 
96
96
  def check_user_containers!(images_ids)
97
97
  return if images_ids.empty?
98
- run_command(%(#{host_docker} ps -a -q #{images_ids.uniq.map { |image_id| "--filter=ancestor=#{image_id}" }.join(' ')} --no-trunc)).tap do |res|
99
- raise Error::Command, code: :user_containers_detected, data: { ids: res.stdout.strip } if res && !res.stdout.strip.empty? && !dry_run?
98
+ log_step_with_indent(:'check user containers') do
99
+ run_command(%(#{host_docker} ps -a -q #{images_ids.uniq.map { |image_id| "--filter=ancestor=#{image_id}" }.join(' ')} --no-trunc)).tap do |res|
100
+ raise Error::Command, code: :user_containers_detected, data: { ids: res.stdout.strip } if res && !res.stdout.strip.empty? && !dry_run?
101
+ end
100
102
  end
101
103
  end
102
104
 
@@ -148,10 +150,6 @@ module Dapp
148
150
  log_step_with_indent(:'proper cache', &blk)
149
151
  end
150
152
 
151
- def log_proper_repo_cache(&blk)
152
- log_step_with_indent(:'proper repo cache', &blk)
153
- end
154
-
155
153
  def one_dimg!
156
154
  return if build_configs.one?
157
155
  raise Error::Command, code: :command_unexpected_dimgs_number, data: { dimgs_names: build_configs.map(&:_name).join(' ') }
@@ -169,13 +167,6 @@ module Dapp
169
167
  '%{repo}:%{tag}'
170
168
  end
171
169
 
172
- def option_repo
173
- unless options[:repo].nil?
174
- return "localhost:5000/#{name}" if options[:repo] == ':minikube'
175
- options[:repo]
176
- end
177
- end
178
-
179
170
  def with_stages?
180
171
  !!options[:with_stages]
181
172
  end
@@ -21,7 +21,9 @@ module Dapp
21
21
  def proper_cache
22
22
  log_proper_cache do
23
23
  lock("#{name}.images") do
24
- remove_project_images(dapp_project_images_ids.select { |image_id| !actual_cache_project_images_ids.include?(image_id) })
24
+ log_step_with_indent(name) do
25
+ remove_project_images(dapp_project_images_ids.select { |image_id| !actual_cache_project_images_ids.include?(image_id) })
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -36,15 +38,15 @@ module Dapp
36
38
  end
37
39
 
38
40
  def stages_cleanup_by_repo
39
- log_proper_repo_cache do
40
- lock("#{name}.images") do
41
- registry = registry(option_repo)
42
- repo_dimgs = repo_detailed_dimgs_images(registry)
41
+ registry = dimg_registry(option_repo)
42
+ repo_dimgs = repo_dimgs_images(registry)
43
43
 
44
+ lock("#{name}.images") do
45
+ log_step_with_indent(name) do
44
46
  dapp_project_dangling_images_flush
45
47
 
46
- _, dimgstages = dapp_project_images.partition { |image| repo_dimgs.any? { |dimg| dimg[:id] == image[:id] } }
47
- repo_dimgs.each { |repo_dimg| except_dapp_project_image_with_parents(repo_dimg[:parent], dimgstages) }
48
+ dimgs, dimgstages = dapp_project_images.partition { |image| repo_dimgs.any? { |dimg| dimg[:id] == image[:id] } }
49
+ dimgs.each { |dimg_image| except_dapp_project_image_with_parents(dimg_image[:id], dimgstages) }
48
50
 
49
51
  # Удаление только образов старше 2ч
50
52
  dimgstages.delete_if do |dimgstage|
@@ -8,7 +8,7 @@ module Dapp
8
8
  lock_repo(repo = option_repo) do
9
9
  raise Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
10
10
 
11
- registry = registry(repo)
11
+ registry = dimg_registry(repo)
12
12
  repo_dimgs = repo_dimgs_images(registry)
13
13
  repo_dimgstages = repo_dimgstages_images(registry)
14
14
 
@@ -6,11 +6,6 @@ module Dapp
6
6
  module Common
7
7
  protected
8
8
 
9
- def registry(repo)
10
- validate_repo_name!(repo)
11
- ::Dapp::Dimg::DockerRegistry.new(repo)
12
- end
13
-
14
9
  def repo_dimgs_images(registry)
15
10
  [].tap do |dimgs_images|
16
11
  with_registry_wrapper do
@@ -55,7 +50,7 @@ module Dapp
55
50
 
56
51
  def delete_repo_image(registry, repo_image)
57
52
  if dry_run?
58
- log(repo_image[:tag])
53
+ log([repo_image[:dimg], repo_image[:tag]].compact.join(':'))
59
54
  else
60
55
  registry.image_delete(repo_image[:tag], repo_image[:dimg])
61
56
  end
@@ -6,9 +6,11 @@ module Dapp
6
6
  module FlushLocal
7
7
  def stages_flush_local
8
8
  lock("#{name}.images") do
9
- dapp_project_containers_flush
10
- dapp_project_dangling_images_flush
11
- remove_project_images(dapp_project_images_ids)
9
+ log_step_with_indent(name) do
10
+ dapp_project_containers_flush
11
+ dapp_project_dangling_images_flush
12
+ remove_project_images(dapp_project_images_ids)
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -7,7 +7,7 @@ module Dapp
7
7
  def stages_flush_repo
8
8
  lock_repo(option_repo) do
9
9
  log_step_with_indent(option_repo) do
10
- registry = registry(option_repo)
10
+ registry = dimg_registry(option_repo)
11
11
  repo_dimgstages_images(registry).each { |repo_image| delete_repo_image(registry, repo_image) }
12
12
  end
13
13
  end
@@ -17,10 +17,6 @@ module Dapp
17
17
  tags.select { |tag| !tag.start_with?('dimgstage') }
18
18
  end
19
19
 
20
- def tags
21
- (@tags ||= {})[repo_suffix] ||= super
22
- end
23
-
24
20
  def image_id(tag, extra_repo_suffix = nil)
25
21
  with_repo_suffix(extra_repo_suffix.to_s) { super(tag) }
26
22
  end
@@ -43,11 +39,6 @@ module Dapp
43
39
  end
44
40
  end
45
41
 
46
- def reset_cache
47
- @tags = nil
48
- @image_history = nil
49
- end
50
-
51
42
  protected
52
43
 
53
44
  def with_repo_suffix(extra_repo_suffix)
@@ -3,8 +3,6 @@ module Dapp
3
3
  module GitRepo
4
4
  # Base class for any Git repo (remote, gitkeeper, etc)
5
5
  class Base
6
- include Helper::Trivia
7
-
8
6
  attr_reader :name
9
7
 
10
8
  def initialize(manager, name)
@@ -86,13 +84,18 @@ module Dapp
86
84
  raise Error::Rugged, code: :git_repository_reference_error, data: { name: name, message: e.message.downcase }
87
85
  end
88
86
 
87
+ def tag_at(name)
88
+ tag = git.tags.find { |t| t.name == name }
89
+ commit_at(tag.target)
90
+ end
91
+
89
92
  def tags
90
- git.tags.map { |t| t.name }
93
+ git.tags.map(&:name)
91
94
  end
92
95
 
93
96
  def remote_branches
94
97
  git.branches
95
- .map { |b| b.name }
98
+ .map(&:name)
96
99
  .select { |b| b.start_with?('origin/') }
97
100
  .map { |b| b.reverse.chomp('origin/'.reverse).reverse }
98
101
  end
@@ -129,6 +132,29 @@ module Dapp
129
132
  def git(**kwargs)
130
133
  @git ||= Rugged::Repository.new(path.to_s, **kwargs)
131
134
  end
135
+
136
+ private
137
+
138
+ def ignore_path?(path, paths: [], exclude_paths: [])
139
+ is_exclude_path = exclude_paths.any? { |p| check_path?(path, p) }
140
+ is_include_path = begin
141
+ paths.empty? ||
142
+ paths.any? { |p| File.fnmatch?(p, path) || File.fnmatch?(File.join(p, '**'), path) }
143
+ end
144
+
145
+ is_exclude_path || !is_include_path
146
+ end
147
+
148
+ def check_path?(path, format)
149
+ path_parts = path.split('/')
150
+ checking_path = nil
151
+
152
+ until path_parts.empty?
153
+ checking_path = [checking_path, path_parts.shift].compact.join('/')
154
+ return true if File.fnmatch(format, checking_path)
155
+ end
156
+ false
157
+ end
132
158
  end
133
159
  end
134
160
  end
@@ -65,9 +65,7 @@ module Dapp
65
65
  def prepare_instructions(options)
66
66
  options.map do |key, vals|
67
67
  case key
68
- when :cmd, :entrypoint
69
- vals = [''] if vals == [] && ::Dapp::Dapp.host_docker_minor_version >= Gem::Version.new('17.10')
70
- [vals]
68
+ when :cmd, :entrypoint then [vals]
71
69
  when :env, :label then vals.map(&method(:options_to_args)).flatten
72
70
  else vals
73
71
  end.map { |val| %(#{key.to_s.upcase} #{val}) }
@@ -28,41 +28,6 @@ module Dapp
28
28
  Pathname.new(File.join(base.to_s, *path.compact.map(&:to_s)))
29
29
  end
30
30
 
31
- def ignore_path?(path, paths: [], exclude_paths: [])
32
- ignore_path_base(path, exclude_paths: exclude_paths) do
33
- paths.empty? ||
34
- paths.any? do |p|
35
- File.fnmatch?(p, path, File::FNM_PATHNAME|File::FNM_DOTMATCH) ||
36
- File.fnmatch?(File.join(p, '**', '*'), path, File::FNM_PATHNAME|File::FNM_DOTMATCH)
37
- end
38
- end
39
- end
40
-
41
- def ignore_path_base(path, exclude_paths: [])
42
- is_exclude_path = exclude_paths.any? { |p| check_path?(path, p) }
43
- is_include_path = yield
44
- is_exclude_path || !is_include_path
45
- end
46
-
47
- def check_path?(path, format)
48
- path_checker(path) { |checking_path| File.fnmatch(format, checking_path, File::FNM_PATHNAME|File::FNM_DOTMATCH) }
49
- end
50
-
51
- def check_subpath?(path, format)
52
- path_checker(format) { |checking_path| File.fnmatch(checking_path, path, File::FNM_PATHNAME|File::FNM_DOTMATCH) }
53
- end
54
-
55
- def path_checker(path)
56
- path_parts = path.split('/')
57
- checking_path = nil
58
-
59
- until path_parts.empty?
60
- checking_path = [checking_path, path_parts.shift].compact.join('/')
61
- return true if yield checking_path
62
- end
63
- false
64
- end
65
-
66
31
  def self.class_to_lowercase(class_name = self)
67
32
  class_name.to_s.split('::').last.split(/(?=[[:upper:]]|[0-9])/).join('_').downcase.to_s
68
33
  end
@@ -69,6 +69,12 @@ BANNER
69
69
  description: 'Default timeout to wait for resources to become ready, 300 seconds by default.',
70
70
  proc: proc {|v| Integer(v)}
71
71
 
72
+ option :without_registry,
73
+ long: "--without-registry",
74
+ default: false,
75
+ boolean: true,
76
+ description: "Do not connect to docker registry to obtain docker image ids of dimgs being deployed."
77
+
72
78
  def run(argv = ARGV)
73
79
  self.class.parse_options(self, argv)
74
80
 
@@ -31,7 +31,8 @@ module Dapp
31
31
  chart_path: kube_chart_path_for_helm,
32
32
  set: self.options[:helm_set_options],
33
33
  values: [*kube_values_paths, *kube_tmp_chart_secret_values_paths],
34
- deploy_timeout: self.options[:timeout] || 300
34
+ deploy_timeout: self.options[:timeout] || 300,
35
+ without_registry: self.options[:without_registry],
35
36
  )
36
37
 
37
38
  yield release
@@ -90,23 +91,138 @@ module Dapp
90
91
 
91
92
  def kube_generate_helm_chart_tpl
92
93
  cont = <<-EOF
93
- {{/* vim: set filetype=mustache: */}}
94
+ {{- define "dapp_secret_file" -}}
95
+ {{- $relative_file_path := index . 0 -}}
96
+ {{- $context := index . 1 -}}
97
+ {{- $context.Files.Get (print "#{kube_tmp_chart_secret_path.subpath_of(kube_chart_path_for_helm)}/" $relative_file_path) -}}
98
+ {{- end -}}
99
+
100
+ {{- define "_dimg" -}}
101
+ {{- $context := index . 0 -}}
102
+ {{- if eq (typeOf $context.Values.global.dapp.docker_image) "map[string]interface {}" -}}
103
+ {{- required "No dimg specified for template" nil -}}
104
+ {{- end -}}
105
+ {{ $context.Values.global.dapp.docker_image }}
106
+ {{- end -}}
107
+
108
+ {{- define "_dimg2" -}}
109
+ {{- $name := index . 0 -}}
110
+ {{- $context := index . 1 -}}
111
+ {{- if ne (typeOf $context.Values.global.dapp.docker_image) "map[string]interface {}" -}}
112
+ {{- required (printf "No dimg should be specified for template, got `%s`" $name) nil -}}
113
+ {{- end -}}
114
+ {{ required (printf "Unknown dimg `%s` specified for template" $name) (pluck $name $context.Values.global.dapp.docker_image | first) }}
115
+ {{- end -}}
94
116
 
95
117
  {{- define "dimg" -}}
96
- {{- if (ge (len (index .)) 2) -}}
97
- {{- $name := index . 0 -}}
98
- {{- $context := index . 1 -}}
99
- {{- printf "%v/%v:%v" $context.Values.global.dapp.repo $name $context.Values.global.dapp.docker_tag -}}
100
- {{- else -}}
101
- {{- $context := index . 0 -}}
102
- {{- printf "%v:%v" $context.Values.global.dapp.repo $context.Values.global.dapp.docker_tag -}}
118
+ {{- if eq (typeOf .) "chartutil.Values" -}}
119
+ {{- $context := . -}}
120
+ {{ tuple $context | include "_dimg" }}
121
+ {{- else if (ge (len .) 2) -}}
122
+ {{- $name := index . 0 -}}
123
+ {{- $context := index . 1 -}}
124
+ {{ tuple $name $context | include "_dimg2" }}
125
+ {{- else -}}
126
+ {{- $context := index . 0 -}}
127
+ {{ tuple $context | include "_dimg" }}
128
+ {{- end -}}
103
129
  {{- end -}}
130
+
131
+ {{- define "_dapp_container__imagePullPolicy" -}}
132
+ {{- $context := index . 0 -}}
133
+ {{- if $context.Values.global.dapp.is_branch -}}
134
+ imagePullPolicy: Always
135
+ {{- end -}}
104
136
  {{- end -}}
105
137
 
106
- {{- define "dapp_secret_file" -}}
107
- {{- $relative_file_path := index . 0 -}}
108
- {{- $context := index . 1 -}}
109
- {{- $context.Files.Get (print "#{kube_tmp_chart_secret_path.subpath_of(kube_chart_path_for_helm)}/" $relative_file_path) -}}
138
+ {{- define "_dapp_container__image" -}}
139
+ {{- $context := index . 0 -}}
140
+ image: {{ tuple $context | include "_dimg" }}
141
+ {{- end -}}
142
+
143
+ {{- define "_dapp_container__image2" -}}
144
+ {{- $name := index . 0 -}}
145
+ {{- $context := index . 1 -}}
146
+ image: {{ tuple $name $context | include "_dimg2" }}
147
+ {{- end -}}
148
+
149
+ {{- define "dapp_container_image" -}}
150
+ {{- if eq (typeOf .) "chartutil.Values" -}}
151
+ {{- $context := . -}}
152
+ {{ tuple $context | include "_dapp_container__image" }}
153
+ {{ tuple $context | include "_dapp_container__imagePullPolicy" }}
154
+ {{- else if (ge (len .) 2) -}}
155
+ {{- $name := index . 0 -}}
156
+ {{- $context := index . 1 -}}
157
+ {{ tuple $name $context | include "_dapp_container__image2" }}
158
+ {{ tuple $context | include "_dapp_container__imagePullPolicy" }}
159
+ {{- else -}}
160
+ {{- $context := index . 0 -}}
161
+ {{ tuple $context | include "_dapp_container__image" }}
162
+ {{ tuple $context | include "_dapp_container__imagePullPolicy" }}
163
+ {{- end -}}
164
+ {{- end -}}
165
+
166
+ {{- define "_dimg_id" -}}
167
+ {{- $context := index . 0 -}}
168
+ {{- if eq (typeOf $context.Values.global.dapp.docker_image_id) "map[string]interface {}" -}}
169
+ {{- required "No dimg specified for template" nil -}}
170
+ {{- end -}}
171
+ {{ $context.Values.global.dapp.docker_image_id }}
172
+ {{- end -}}
173
+
174
+ {{- define "_dimg_id2" -}}
175
+ {{- $name := index . 0 -}}
176
+ {{- $context := index . 1 -}}
177
+ {{- if ne (typeOf $context.Values.global.dapp.docker_image_id) "map[string]interface {}" -}}
178
+ {{- required (printf "No dimg should be specified for template, got `%s`" $name) nil -}}
179
+ {{- end -}}
180
+ {{ required (printf "Unknown dimg `%s` specified for template" $name) (pluck $name $context.Values.global.dapp.docker_image_id | first) }}
181
+ {{- end -}}
182
+
183
+ {{- define "dimg_id" -}}
184
+ {{- if eq (typeOf .) "chartutil.Values" -}}
185
+ {{- $context := . -}}
186
+ {{ tuple $context | include "_dimg_id" }}
187
+ {{- else if (ge (len .) 2) -}}
188
+ {{- $name := index . 0 -}}
189
+ {{- $context := index . 1 -}}
190
+ {{ tuple $name $context | include "_dimg_id2" }}
191
+ {{- else -}}
192
+ {{- $context := index . 0 -}}
193
+ {{ tuple $context | include "_dimg_id" }}
194
+ {{- end -}}
195
+ {{- end -}}
196
+
197
+ {{- define "_dapp_container_env" -}}
198
+ {{- $context := index . 0 -}}
199
+ {{- if $context.Values.global.dapp.is_branch -}}
200
+ - name: DOCKER_IMAGE_ID
201
+ value: {{ tuple $context | include "_dimg_id" }}
202
+ {{- end -}}
203
+ {{- end -}}
204
+
205
+ {{- define "_dapp_container_env2" -}}
206
+ {{- $name := index . 0 -}}
207
+ {{- $context := index . 1 -}}
208
+ {{- if $context.Values.global.dapp.is_branch -}}
209
+ - name: DOCKER_IMAGE_ID
210
+ value: {{ tuple $name $context | include "_dimg_id2" }}
211
+ {{- end -}}
212
+ {{- end -}}
213
+
214
+ {{- define "dapp_container_env" -}}
215
+ {{- if eq (typeOf .) "chartutil.Values" -}}
216
+ {{- $context := . -}}
217
+ {{ tuple $context | include "_dapp_container_env" }}
218
+ {{- else if (ge (len .) 2) -}}
219
+ {{- $name := index . 0 -}}
220
+ {{- $context := index . 1 -}}
221
+ {{ tuple $name $context | include "_dapp_container_env2" }}
222
+ {{- else -}}
223
+ {{- $context := index . 0 -}}
224
+ {{ tuple $context | include "_dapp_container_env" }}
225
+ {{- end -}}
110
226
  {{- end -}}
111
227
  EOF
112
228
  kube_chart_path_for_helm('templates/_dapp_helpers.tpl').write(cont)