dapp 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/en/net_status.yml +4 -2
- data/lib/dapp.rb +2 -1
- data/lib/dapp/dapp.rb +1 -0
- data/lib/dapp/dapp/git_artifact.rb +4 -0
- data/lib/dapp/dapp/option_tags.rb +63 -0
- data/lib/dapp/dimg/build/stage/base.rb +1 -1
- data/lib/dapp/dimg/build/stage/ga_base.rb +1 -1
- data/lib/dapp/dimg/cli/command/dimg/stages.rb +4 -4
- data/lib/dapp/dimg/cli/command/dimg/stages/cleanup_local.rb +2 -4
- data/lib/dapp/dimg/cli/command/dimg/stages/cleanup_repo.rb +1 -3
- data/lib/dapp/dimg/cli/command/dimg/stages/flush_local.rb +2 -4
- data/lib/dapp/dimg/cli/command/dimg/stages/flush_repo.rb +2 -4
- data/lib/dapp/dimg/dapp/command/common.rb +1 -1
- data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +9 -9
- data/lib/dapp/dimg/dapp/command/stages/cleanup_repo.rb +42 -51
- data/lib/dapp/dimg/dapp/command/stages/common.rb +33 -25
- data/lib/dapp/dimg/dapp/command/stages/flush_repo.rb +2 -2
- data/lib/dapp/dimg/dapp/dappfile.rb +8 -0
- data/lib/dapp/dimg/dimg.rb +1 -2
- data/lib/dapp/dimg/docker_registry.rb +1 -1
- data/lib/dapp/dimg/docker_registry/base.rb +3 -5
- data/lib/dapp/dimg/docker_registry/default.rb +1 -1
- data/lib/dapp/dimg/docker_registry/dimg.rb +58 -0
- data/lib/dapp/dimg/git_artifact.rb +21 -21
- data/lib/dapp/dimg/git_repo/base.rb +24 -3
- data/lib/dapp/dimg/git_repo/own.rb +4 -4
- data/lib/dapp/dimg/git_repo/remote.rb +3 -3
- data/lib/dapp/kube/cli/command/kube/deploy.rb +25 -3
- data/lib/dapp/kube/cli/command/kube/lint.rb +36 -14
- data/lib/dapp/kube/cli/command/kube/render.rb +25 -3
- data/lib/dapp/kube/dapp/command/common.rb +9 -5
- data/lib/dapp/kube/dapp/command/lint.rb +3 -3
- data/lib/dapp/kube/helm/release.rb +4 -4
- data/lib/dapp/version.rb +1 -1
- metadata +4 -3
- data/lib/dapp/dimg/dimg/tags.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03083f145a1b261c09f5ac85cb210498603ae8255b9d1caf8f4a20f1c44781a5
|
4
|
+
data.tar.gz: 042aaa870856b1141411106909baa1d6e7e880ca43d9b87b037c09f5dc37f4ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a337d11f46ccda094b8295a245e1416a1e0027fe23b1738181c77d1619eb79172c81d7c1a1040050d52c93227b9f6d4f9d70d866589b0edc5fc02c9edd1ed359
|
7
|
+
data.tar.gz: 59f31c8087e4c50b22e8135bbe943887322bd4ab021f51029d008d30a236e8ecbffa896c451c94c6989276599201e063e67c6c583860d760b5291a36749a4f8e
|
data/config/en/net_status.yml
CHANGED
@@ -6,8 +6,6 @@ en:
|
|
6
6
|
dimg:
|
7
7
|
dimg_not_built: "Dimg hasn't been built yet!"
|
8
8
|
dimg_not_run: "Dimg run failed!"
|
9
|
-
git_branch_without_name: "Dimg has specific revision that isn't associated with a branch name!"
|
10
|
-
ci_environment_required: 'CI environment required (Travis or GitLab CI)!'
|
11
9
|
kube:
|
12
10
|
deploy_timeout: "Deploy timeout!"
|
13
11
|
dappfile:
|
@@ -44,6 +42,7 @@ en:
|
|
44
42
|
user_containers_detected: "User containers are using these images:\n%{ids}"
|
45
43
|
incorrect_yaml_structure: "Incorrect YAML structure in `%{path}`!"
|
46
44
|
editor_not_found: "Editor not found!"
|
45
|
+
expected_only_one_tag: 'Expected only one tag (`%{tags}`)!'
|
47
46
|
dapp:
|
48
47
|
no_such_dimg: "No such dimg: `%{dimgs_patterns}`!"
|
49
48
|
no_such_app: "No such app: `%{apps_patterns}`!"
|
@@ -57,6 +56,8 @@ en:
|
|
57
56
|
yaml_incorrect: "`%{message}`"
|
58
57
|
incorrect_dapp_config_option: ".dapp_config includes option `%{option}` with incorrect value `%{value}`: expected one of the following types [%{expected}]"
|
59
58
|
incorrect_dapp_config_option_color: ".dapp_config includes option `color` with incorrect value `%{value}`: expected one of the following values [%{expected}]"
|
59
|
+
ci_environment_required: 'CI environment required (Travis or GitLab CI)!'
|
60
|
+
git_branch_without_name: "Dimg has specific revision that isn't associated with a branch name!"
|
60
61
|
config:
|
61
62
|
dimg_name_required: 'Dimg name required!'
|
62
63
|
dimg_name_incorrect: "Dimg has incorrect name `%{value}`: doesn't match regex `%{pattern}`!"
|
@@ -108,6 +109,7 @@ en:
|
|
108
109
|
no_such_dimg: 'Registry `%{registry}`: no such dimg in registry!'
|
109
110
|
authenticate_type_not_supported: 'Registry `%{registry}`: authenticate type is not supported!'
|
110
111
|
page_not_found: "Registry `%{registry}`: page `%{url}` not found!"
|
112
|
+
method_not_allowed: "Registry `%{registry}`: method `%{method}` not allowed (`%{url}`)!"
|
111
113
|
user_not_authorized: 'Registry `%{registry}`: user not authorized!'
|
112
114
|
rugged:
|
113
115
|
git_repository_reference_error: "Git repo `%{name}`: %{message}!"
|
data/lib/dapp.rb
CHANGED
@@ -53,6 +53,7 @@ require 'dapp/dapp/git_artifact'
|
|
53
53
|
require 'dapp/dapp/dappfile'
|
54
54
|
require 'dapp/dapp/chef'
|
55
55
|
require 'dapp/dapp/dapp_config'
|
56
|
+
require 'dapp/dapp/option_tags'
|
56
57
|
require 'dapp/dapp/logging/base'
|
57
58
|
require 'dapp/dapp/logging/process'
|
58
59
|
require 'dapp/dapp/logging/paint'
|
@@ -258,6 +259,7 @@ require 'dapp/dimg/docker_registry'
|
|
258
259
|
require 'dapp/dimg/docker_registry/base/request'
|
259
260
|
require 'dapp/dimg/docker_registry/base/authorization'
|
260
261
|
require 'dapp/dimg/docker_registry/base'
|
262
|
+
require 'dapp/dimg/docker_registry/dimg'
|
261
263
|
require 'dapp/dimg/docker_registry/default'
|
262
264
|
require 'dapp/dimg/error/base'
|
263
265
|
require 'dapp/dimg/error/dimg'
|
@@ -285,7 +287,6 @@ require 'dapp/dimg/image/stage'
|
|
285
287
|
require 'dapp/dimg/image/scratch'
|
286
288
|
require 'dapp/dimg/dimg/git_artifact'
|
287
289
|
require 'dapp/dimg/dimg/path'
|
288
|
-
require 'dapp/dimg/dimg/tags'
|
289
290
|
require 'dapp/dimg/dimg/stages'
|
290
291
|
require 'dapp/dimg/dimg'
|
291
292
|
require 'dapp/dimg/artifact'
|
data/lib/dapp/dapp.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Dapp
|
2
|
+
class Dapp
|
3
|
+
module OptionTags
|
4
|
+
def git_local_repo
|
5
|
+
@git_repo ||= ::Dapp::Dimg::GitRepo::Own.new(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
def option_tags
|
9
|
+
@tags ||= begin
|
10
|
+
tags = simple_tags + branch_tags + commit_tags + build_tags + ci_tags
|
11
|
+
tags << :latest if tags.empty?
|
12
|
+
tags
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def simple_tags
|
17
|
+
options[:tag]
|
18
|
+
end
|
19
|
+
|
20
|
+
def branch_tags
|
21
|
+
return [] unless options[:tag_branch]
|
22
|
+
raise Error::Dapp, code: :git_branch_without_name if (branch = git_local_repo.branch) == 'HEAD'
|
23
|
+
[branch]
|
24
|
+
end
|
25
|
+
|
26
|
+
def commit_tags
|
27
|
+
return [] unless options[:tag_commit]
|
28
|
+
commit = git_local_repo.latest_commit
|
29
|
+
[commit]
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_tags
|
33
|
+
return [] unless options[:tag_build_id]
|
34
|
+
|
35
|
+
if ENV['GITLAB_CI']
|
36
|
+
build_id = ENV['CI_BUILD_ID']
|
37
|
+
elsif ENV['TRAVIS']
|
38
|
+
build_id = ENV['TRAVIS_BUILD_NUMBER']
|
39
|
+
else
|
40
|
+
raise Error::Dapp, code: :ci_environment_required
|
41
|
+
end
|
42
|
+
|
43
|
+
[build_id]
|
44
|
+
end
|
45
|
+
|
46
|
+
def ci_tags
|
47
|
+
return [] unless options[:tag_ci]
|
48
|
+
|
49
|
+
if ENV['GITLAB_CI']
|
50
|
+
branch = ENV['CI_BUILD_REF_NAME']
|
51
|
+
tag = ENV['CI_BUILD_TAG']
|
52
|
+
elsif ENV['TRAVIS']
|
53
|
+
branch = ENV['TRAVIS_BRANCH']
|
54
|
+
tag = ENV['TRAVIS_TAG']
|
55
|
+
else
|
56
|
+
raise Error::Dapp, code: :ci_environment_required
|
57
|
+
end
|
58
|
+
|
59
|
+
[branch, tag].compact
|
60
|
+
end
|
61
|
+
end # Tags
|
62
|
+
end # Dapp
|
63
|
+
end # Dapp
|
@@ -191,7 +191,7 @@ module Dapp
|
|
191
191
|
def layer_commit(git_artifact)
|
192
192
|
commits[git_artifact] ||= begin
|
193
193
|
if image.tagged?
|
194
|
-
image.labels[
|
194
|
+
image.labels[dimg.dapp.dimgstage_ga_label(git_artifact.paramshash)]
|
195
195
|
else
|
196
196
|
git_artifact.latest_commit
|
197
197
|
end
|
@@ -10,7 +10,7 @@ module Dapp
|
|
10
10
|
image.add_volume "#{dimg.tmp_path('patches')}:#{dimg.container_tmp_path('patches')}:ro"
|
11
11
|
|
12
12
|
dimg.git_artifacts.each do |git_artifact|
|
13
|
-
image.add_service_change_label(
|
13
|
+
image.add_service_change_label(dimg.dapp.dimgstage_ga_label(git_artifact.paramshash).to_sym => git_artifact.latest_commit)
|
14
14
|
image.add_command git_artifact.send(apply_command_method, self)
|
15
15
|
end
|
16
16
|
end
|
@@ -7,10 +7,10 @@ module Dapp::Dimg::CLI
|
|
7
7
|
banner <<BANNER.freeze
|
8
8
|
Available subcommands: (for details, dapp dimg stages SUB-COMMAND --help)
|
9
9
|
|
10
|
-
dapp dimg stages cleanup local [options] [
|
11
|
-
dapp dimg stages cleanup repo [options]
|
12
|
-
dapp dimg stages flush local [options]
|
13
|
-
dapp dimg stages flush repo [options]
|
10
|
+
dapp dimg stages cleanup local [options] [REPO]
|
11
|
+
dapp dimg stages cleanup repo [options] REPO
|
12
|
+
dapp dimg stages flush local [options]
|
13
|
+
dapp dimg stages flush repo [options] REPO
|
14
14
|
dapp dimg stages push [options] [DIMG ...] REPO
|
15
15
|
dapp dimg stages pull [options] [DIMG ...] REPO
|
16
16
|
|
@@ -6,9 +6,7 @@ module Dapp::Dimg::CLI
|
|
6
6
|
banner <<BANNER.freeze
|
7
7
|
Usage:
|
8
8
|
|
9
|
-
dapp dimg stages cleanup local [options] [
|
10
|
-
|
11
|
-
DIMG Dapp image to process [default: *].
|
9
|
+
dapp dimg stages cleanup local [options] [REPO]
|
12
10
|
|
13
11
|
Options:
|
14
12
|
BANNER
|
@@ -33,7 +31,7 @@ BANNER
|
|
33
31
|
def run(argv = ARGV)
|
34
32
|
self.class.parse_options(self, argv)
|
35
33
|
repository = repo
|
36
|
-
run_dapp_command(run_method, options: cli_options(
|
34
|
+
run_dapp_command(run_method, options: cli_options(repo: repository))
|
37
35
|
end
|
38
36
|
|
39
37
|
def repo
|
@@ -6,15 +6,13 @@ module Dapp::Dimg::CLI
|
|
6
6
|
banner <<BANNER.freeze
|
7
7
|
Usage:
|
8
8
|
|
9
|
-
dapp dimg stages flush local [options]
|
10
|
-
|
11
|
-
DIMG Dapp image to process [default: *].
|
9
|
+
dapp dimg stages flush local [options]
|
12
10
|
|
13
11
|
Options:
|
14
12
|
BANNER
|
15
13
|
def run(argv = ARGV)
|
16
14
|
self.class.parse_options(self, argv)
|
17
|
-
run_dapp_command(:stages_flush_local, options: cli_options
|
15
|
+
run_dapp_command(:stages_flush_local, options: cli_options)
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
@@ -6,9 +6,7 @@ module Dapp::Dimg::CLI
|
|
6
6
|
banner <<BANNER.freeze
|
7
7
|
Usage:
|
8
8
|
|
9
|
-
dapp dimg stages flush repo [options]
|
10
|
-
|
11
|
-
DIMG Dapp image to process [default: *].
|
9
|
+
dapp dimg stages flush repo [options] REPO
|
12
10
|
|
13
11
|
Options:
|
14
12
|
BANNER
|
@@ -21,7 +19,7 @@ BANNER
|
|
21
19
|
def run(argv = ARGV)
|
22
20
|
self.class.parse_options(self, argv)
|
23
21
|
repo = self.class.required_argument(self, 'repo')
|
24
|
-
run_dapp_command(:stages_flush_repo, options: cli_options(
|
22
|
+
run_dapp_command(:stages_flush_repo, options: cli_options(repo: repo))
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -45,29 +45,29 @@ module Dapp
|
|
45
45
|
log_step_with_indent(name) do
|
46
46
|
dapp_project_dangling_images_flush
|
47
47
|
|
48
|
-
dimgs,
|
49
|
-
dimgs.each { |dimg_image| except_dapp_project_image_with_parents(dimg_image[:id],
|
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) }
|
50
50
|
|
51
51
|
# Удаление только образов старше 2ч
|
52
|
-
|
53
|
-
Time.now -
|
52
|
+
dimgstages.delete_if do |dimgstage|
|
53
|
+
Time.now - dimgstage[:created_at] < 2*60*60
|
54
54
|
end
|
55
55
|
|
56
|
-
remove_project_images(
|
56
|
+
remove_project_images(dimgstages.map { |dimgstage| dimgstage[:id]} )
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def except_dapp_project_image_with_parents(image_id,
|
61
|
+
def except_dapp_project_image_with_parents(image_id, dimgstages)
|
62
62
|
if dapp_project_image_exist?(image_id)
|
63
|
-
dapp_project_image_artifacts_ids_in_labels(image_id).each { |aiid| except_dapp_project_image_with_parents(aiid,
|
63
|
+
dapp_project_image_artifacts_ids_in_labels(image_id).each { |aiid| except_dapp_project_image_with_parents(aiid, dimgstages) }
|
64
64
|
iid = image_id
|
65
65
|
loop do
|
66
|
-
|
66
|
+
dimgstages.delete_if { |dimgstage| dimgstage[:id] == iid }
|
67
67
|
break if (iid = dapp_project_image_parent_id(iid)).nil?
|
68
68
|
end
|
69
69
|
else
|
70
|
-
|
70
|
+
dimgstages.delete_if { |dimgstage| dimgstage[:id] == dimgstage }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -10,89 +10,80 @@ module Dapp
|
|
10
10
|
|
11
11
|
registry = registry(repo)
|
12
12
|
repo_dimgs = repo_dimgs_images(registry)
|
13
|
-
|
13
|
+
repo_dimgstages = repo_dimgstages_images(registry)
|
14
14
|
|
15
|
-
|
15
|
+
repo_dimgstages.delete_if { |dimgstage| repo_dimgs.any? { |dimg| dimgstage[:id] == dimg[:id] } } # ignoring stages with dimgs ids (v2)
|
16
16
|
|
17
|
-
proper_repo_cache(registry,
|
18
|
-
|
19
|
-
proper_repo_git_commit(registry)
|
17
|
+
proper_repo_cache(registry, repo_dimgstages) if proper_cache_version?
|
18
|
+
repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages) if proper_repo_cache?
|
19
|
+
proper_repo_git_commit(registry) if proper_git_commit?
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
protected
|
24
24
|
|
25
|
-
def proper_repo_cache(registry,
|
25
|
+
def proper_repo_cache(registry, repo_dimgstages)
|
26
26
|
log_proper_cache do
|
27
|
-
|
28
|
-
repo_image_dapp_cache_version_label(registry,
|
29
|
-
|
30
|
-
wrong_cache_images.each { |image_tag, _| delete_repo_image(registry, image_tag) }
|
31
|
-
repo_stages.delete_if { |image_tag, _| wrong_cache_images.keys.include?(image_tag) }
|
27
|
+
repo_dimgstages
|
28
|
+
.select { |dimgstage| repo_image_dapp_cache_version_label(registry, dimgstage) != ::Dapp::BUILD_CACHE_VERSION.to_s }
|
29
|
+
.each { |dimgstage| delete_repo_image(registry, dimgstage); repo_dimgstages.delete_at(repo_dimgstages.index(dimgstage)) }
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
33
|
+
def repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages)
|
36
34
|
log_step_with_indent(option_repo) do
|
37
|
-
repo_dimgs.each { |
|
38
|
-
|
35
|
+
repo_dimgs.each { |dimg| except_repo_image_with_parents(registry, repo_dimgstages, dimg) }
|
36
|
+
repo_dimgstages.each { |dimgstage| delete_repo_image(registry, dimgstage) }
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
repo_image_dapp_artifacts_labels(registry,
|
44
|
-
|
45
|
-
|
40
|
+
def except_repo_image_with_parents(registry, repo_dimgstages, repo_image)
|
41
|
+
repo_image_dapp_artifacts_labels(registry, repo_image).each do |aid|
|
42
|
+
repo_image = find_repo_image_by_id(repo_dimgstages, aid)
|
43
|
+
except_repo_image_with_parents(registry, repo_dimgstages, repo_image) unless repo_image.nil?
|
46
44
|
end
|
47
45
|
|
48
|
-
itag = image_tag
|
49
|
-
iid = image_id
|
50
46
|
loop do
|
51
|
-
|
52
|
-
break if
|
53
|
-
|
47
|
+
repo_dimgstages.delete_if { |dimgstage| dimgstage[:id] == repo_image[:id] }
|
48
|
+
break if begin
|
49
|
+
(iid = registry.image_parent_id(repo_image[:tag], repo_image[:dimg])).empty? ||
|
50
|
+
(repo_image = find_repo_image_by_id(repo_dimgstages, iid)).nil?
|
51
|
+
end
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
def repo_image_dapp_artifacts_labels(registry,
|
58
|
-
select_dapp_artifacts_ids(registry.image_labels(
|
55
|
+
def repo_image_dapp_artifacts_labels(registry, repo_image)
|
56
|
+
select_dapp_artifacts_ids(registry.image_labels(repo_image[:tag], repo_image[:dimg]))
|
59
57
|
end
|
60
58
|
|
61
|
-
def repo_image_dapp_cache_version_label(registry,
|
62
|
-
registry.image_labels(
|
59
|
+
def repo_image_dapp_cache_version_label(registry, repo_image)
|
60
|
+
registry.image_labels(repo_image[:tag], repo_image[:dimg])['dapp-cache-version']
|
63
61
|
end
|
64
62
|
|
65
|
-
def
|
66
|
-
|
67
|
-
nil
|
63
|
+
def find_repo_image_by_id(repo_images, repo_image_id)
|
64
|
+
repo_images.find { |repo_image| repo_image[:id] == repo_image_id }
|
68
65
|
end
|
69
66
|
|
70
67
|
def proper_repo_git_commit(registry)
|
71
68
|
log_proper_git_commit do
|
72
69
|
unproper_images = []
|
73
|
-
|
74
|
-
|
70
|
+
repo_detailed_dimgstage_images(registry).each do |dimgstage|
|
71
|
+
dimgstage[:labels].each do |repo_name, commit|
|
75
72
|
next if (repo = dapp_git_repositories[repo_name]).nil?
|
76
|
-
unproper_images.concat(repo_image_tags_hierarchy(registry,
|
73
|
+
unproper_images.concat(repo_image_tags_hierarchy(registry, dimgstage[:id])) unless repo.commit_exists?(commit)
|
77
74
|
end
|
78
75
|
end
|
79
|
-
|
76
|
+
remove_repo_dapp_dimgstage_images(registry, unproper_images.uniq)
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
83
|
-
def
|
84
|
-
@
|
85
|
-
registry.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
id: registry.image_id(tag),
|
91
|
-
parent: image_history['container_config']['Image'],
|
92
|
-
labels: image_history['config']['Labels']
|
93
|
-
}
|
94
|
-
[tag, attrs]
|
95
|
-
end.compact
|
80
|
+
def repo_detailed_dimgstage_images(registry)
|
81
|
+
@repo_dapp_dimgstage_images_detailed ||= begin
|
82
|
+
repo_dimgstages_images(registry).each do |dimgstage|
|
83
|
+
image_history = registry.image_history(dimgstage[:tag], nil)
|
84
|
+
dimgstage[:parent] = image_history['container_config']['Image']
|
85
|
+
dimgstage[:labels] = image_history['config']['Labels']
|
86
|
+
end
|
96
87
|
end
|
97
88
|
end
|
98
89
|
|
@@ -104,18 +95,18 @@ module Dapp
|
|
104
95
|
hierarchy.concat(iids)
|
105
96
|
break if begin
|
106
97
|
iids.map! do |iid|
|
107
|
-
|
98
|
+
repo_detailed_dimgstage_images(registry).map { |dimgstage| dimgstage[:id] if dimgstage[:parent] == iid }.compact
|
108
99
|
end.flatten!.empty?
|
109
100
|
end
|
110
101
|
end
|
111
102
|
|
112
|
-
|
103
|
+
repo_detailed_dimgstage_images(registry).map { |dimgstage| dimgstage[:tag] if hierarchy.include? dimgstage[:id] }.compact
|
113
104
|
end
|
114
105
|
|
115
|
-
def
|
106
|
+
def remove_repo_dapp_dimgstage_images(registry, tags)
|
116
107
|
tags.each do |tag|
|
117
108
|
log(tag) if log_verbose? || dry_run?
|
118
|
-
registry.image_delete(tag) unless dry_run?
|
109
|
+
registry.image_delete(tag, nil) unless dry_run?
|
119
110
|
end
|
120
111
|
end
|
121
112
|
end
|
@@ -12,44 +12,52 @@ module Dapp
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def repo_dimgs_images(registry)
|
15
|
-
|
15
|
+
@repo_dimgs_images ||= [].tap do |dimgs_images|
|
16
|
+
with_registry_wrapper do
|
17
|
+
{}.tap do |dimgs_tags|
|
18
|
+
dimgs_tags[nil] = registry.nameless_dimg_tags
|
19
|
+
dimgs_names.each do |dimg_name|
|
20
|
+
dimgs_tags[dimg_name] = registry.dimg_tags(dimg_name)
|
21
|
+
end unless nameless_dimg?
|
22
|
+
end.each do |dimg_name, tags|
|
23
|
+
dimgs_images.concat(tags_to_repo_images(registry, tags, dimg_name))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
|
-
def
|
19
|
-
|
29
|
+
def repo_dimgstages_images(registry)
|
30
|
+
with_registry_wrapper do
|
31
|
+
tags_to_repo_images(registry, registry.dimgstages_tags)
|
32
|
+
end
|
20
33
|
end
|
21
34
|
|
22
|
-
def
|
23
|
-
|
24
|
-
format = proc do |arr|
|
25
|
-
arr.map do |tag|
|
26
|
-
if (id = registry.image_id(tag)).nil?
|
27
|
-
log_warning(desc: { code: 'tag_ignored', data: { tag: tag } })
|
28
|
-
else
|
29
|
-
[tag, id]
|
30
|
-
end
|
31
|
-
end.compact.to_h
|
32
|
-
end
|
33
|
-
dimgs, stages = registry_tags(registry).partition { |tag| !tag.start_with?('dimgstage') }
|
34
|
-
|
35
|
-
images[:dimgs] = format.call(dimgs)
|
36
|
-
images[:stages] = format.call(stages)
|
37
|
-
end
|
35
|
+
def tags_to_repo_images(registry, tags, dimg_name = nil)
|
36
|
+
tags.map { |tag| repo_image_format(registry, tag, dimg_name) }.compact
|
38
37
|
end
|
39
38
|
|
40
|
-
def
|
41
|
-
|
39
|
+
def with_registry_wrapper
|
40
|
+
yield
|
42
41
|
rescue Exception::Registry => e
|
43
42
|
raise unless e.net_status[:code] == :no_such_dimg
|
44
43
|
log_warning(desc: { code: :dimg_not_found_in_registry })
|
45
44
|
[]
|
46
45
|
end
|
47
46
|
|
48
|
-
def
|
47
|
+
def repo_image_format(registry, tag, dimg_name = nil)
|
48
|
+
if (id = registry.image_id(tag, dimg_name)).nil?
|
49
|
+
log_warning(desc: { code: 'tag_ignored', data: { tag: tag } })
|
50
|
+
nil
|
51
|
+
else
|
52
|
+
{ dimg: dimg_name, tag: tag, id: id }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_repo_image(registry, repo_image)
|
49
57
|
if dry_run?
|
50
|
-
log(
|
58
|
+
log(repo_image[:tag])
|
51
59
|
else
|
52
|
-
registry.image_delete(
|
60
|
+
registry.image_delete(repo_image[:tag], repo_image[:dimg])
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
@@ -64,7 +72,7 @@ module Dapp
|
|
64
72
|
dimgs.each do |dimg|
|
65
73
|
[dimg, dimg.artifacts].flatten
|
66
74
|
.map(&:git_artifacts).flatten
|
67
|
-
.map { |ga_artifact| repositories[ga_artifact.
|
75
|
+
.map { |ga_artifact| repositories[dimgstage_ga_label(ga_artifact.paramshash)] = ga_artifact.repo }
|
68
76
|
end
|
69
77
|
end
|
70
78
|
end
|
@@ -9,9 +9,9 @@ module Dapp
|
|
9
9
|
log_step_with_indent(option_repo) do
|
10
10
|
registry = registry(option_repo)
|
11
11
|
repo_dimgs = repo_dimgs_images(registry)
|
12
|
-
|
12
|
+
repo_dimgstages = repo_dimgstages_images(registry)
|
13
13
|
|
14
|
-
repo_dimgs.
|
14
|
+
repo_dimgs.concat(repo_dimgstages).each { |repo_image| delete_repo_image(registry, repo_image) }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/dapp/dimg/dimg.rb
CHANGED
@@ -3,7 +3,6 @@ module Dapp
|
|
3
3
|
class Dimg
|
4
4
|
include GitArtifact
|
5
5
|
include Path
|
6
|
-
include Tags
|
7
6
|
include Stages
|
8
7
|
|
9
8
|
include Helper::Sha256
|
@@ -62,7 +61,7 @@ module Dapp
|
|
62
61
|
|
63
62
|
def export!(repo, format:)
|
64
63
|
dapp.lock("#{dapp.name}.images", readonly: true) do
|
65
|
-
|
64
|
+
dapp.option_tags.each do |tag|
|
66
65
|
image_name = format(format, repo: repo, dimg_name: config._name, tag: tag)
|
67
66
|
export_base!(last_stage.image, image_name)
|
68
67
|
end
|
@@ -9,7 +9,7 @@ module Dapp
|
|
9
9
|
if expected_hostname
|
10
10
|
%w(https http).each do |protocol|
|
11
11
|
expected_hostname_url = [protocol, expected_hostname].join('://')
|
12
|
-
return
|
12
|
+
return Dimg.new(repo, expected_hostname_url, expected_repo_suffix) if hostname_exist?(expected_hostname_url)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
Default.new(repo, File.join(*[expected_hostname, expected_repo_suffix].compact))
|
@@ -17,12 +17,8 @@ module Dapp
|
|
17
17
|
self.repo_suffix = repo_suffix
|
18
18
|
end
|
19
19
|
|
20
|
-
def repo_exist?
|
21
|
-
tags.any?
|
22
|
-
end
|
23
|
-
|
24
20
|
def tags
|
25
|
-
|
21
|
+
api_request(repo_suffix, 'tags/list')['tags'] || []
|
26
22
|
rescue Error::Registry => e
|
27
23
|
raise Exception::Registry, code: :no_such_dimg, data: { registry: api_url } if e.net_status[:code] == :page_not_found
|
28
24
|
raise
|
@@ -86,6 +82,8 @@ module Dapp
|
|
86
82
|
def raw_api_request(*uri, **options)
|
87
83
|
url = api_url(*uri)
|
88
84
|
request(url, **default_api_options.merge(options))
|
85
|
+
rescue Excon::Error::MethodNotAllowed
|
86
|
+
raise Error::Registry, code: :method_not_allowed, data: { url: url, registry: api_url, method: options[:method] }
|
89
87
|
rescue Excon::Error::NotFound
|
90
88
|
raise Error::Registry, code: :page_not_found, data: { url: url, registry: api_url }
|
91
89
|
rescue Excon::Error::Unauthorized
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Dimg
|
3
|
+
module DockerRegistry
|
4
|
+
class Dimg < Base
|
5
|
+
def dimgstages_tags
|
6
|
+
tags.select { |tag| tag.start_with?('dimgstage') }
|
7
|
+
end
|
8
|
+
|
9
|
+
def dimg_tags(dimg_name)
|
10
|
+
with_repo_suffix(dimg_name.to_s) { tags }
|
11
|
+
rescue Exception::Registry => e
|
12
|
+
raise unless e.net_status[:code] == :no_such_dimg
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
def nameless_dimg_tags
|
17
|
+
tags.select { |tag| !tag.start_with?('dimgstage') }
|
18
|
+
end
|
19
|
+
|
20
|
+
def tags
|
21
|
+
(@tags ||= {})[repo_suffix] ||= super
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_id(tag, extra_repo_suffix = nil)
|
25
|
+
with_repo_suffix(extra_repo_suffix.to_s) { super(tag) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def image_parent_id(tag, extra_repo_suffix = nil)
|
29
|
+
with_repo_suffix(extra_repo_suffix.to_s) { super(tag) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def image_labels(tag, extra_repo_suffix = nil)
|
33
|
+
with_repo_suffix(extra_repo_suffix.to_s) { super(tag) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def image_delete(tag, extra_repo_suffix = nil)
|
37
|
+
with_repo_suffix(extra_repo_suffix.to_s) { super(tag) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def image_history(tag, extra_repo_suffix = nil)
|
41
|
+
with_repo_suffix(extra_repo_suffix.to_s) do
|
42
|
+
(@image_history ||= {})[[repo_suffix, tag]] ||= super(tag)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def with_repo_suffix(extra_repo_suffix)
|
49
|
+
old_repo_suffix = repo_suffix
|
50
|
+
@repo_suffix = File.join(repo_suffix, extra_repo_suffix)
|
51
|
+
yield
|
52
|
+
ensure
|
53
|
+
@repo_suffix = old_repo_suffix
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end # DockerRegistry
|
57
|
+
end # Dimg
|
58
|
+
end # Dapp
|
@@ -16,7 +16,7 @@ module Dapp
|
|
16
16
|
@repo = repo
|
17
17
|
@name = name
|
18
18
|
|
19
|
-
@branch = branch || repo.
|
19
|
+
@branch = branch || repo.dapp.options[:git_artifact_branch] || repo.branch
|
20
20
|
@commit = commit
|
21
21
|
|
22
22
|
@to = to
|
@@ -67,13 +67,13 @@ module Dapp
|
|
67
67
|
when :directory
|
68
68
|
stage.image.add_service_change_label :"dapp-git-#{paramshash}-type" => 'directory'
|
69
69
|
|
70
|
-
commands << "#{repo.
|
71
|
-
commands << "#{sudo}#{repo.
|
70
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
71
|
+
commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage, *archive_stage_commit(stage))} -C \"#{to}\""
|
72
72
|
when :file
|
73
73
|
stage.image.add_service_change_label :"dapp-git-#{paramshash}-type" => 'file'
|
74
74
|
|
75
|
-
commands << "#{repo.
|
76
|
-
commands << "#{sudo}#{repo.
|
75
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
76
|
+
commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage, *archive_stage_commit(stage))} -C \"#{File.dirname(to)}\""
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -90,13 +90,13 @@ module Dapp
|
|
90
90
|
case archive_type
|
91
91
|
when :directory
|
92
92
|
changed_files = diff_patches(*dev_patch_stage_commits(stage)).map {|p| "\"#{File.join(to, cwd, p.delta.new_file[:path])}\""}
|
93
|
-
commands << "#{repo.
|
94
|
-
commands << "#{repo.
|
95
|
-
commands << "#{sudo}#{repo.
|
93
|
+
commands << "#{repo.dapp.rm_bin} -rf #{changed_files.join(' ')}"
|
94
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
95
|
+
commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage, *dev_patch_stage_commits(stage))} -C \"#{to}\""
|
96
96
|
when :file
|
97
|
-
commands << "#{repo.
|
98
|
-
commands << "#{repo.
|
99
|
-
commands << "#{sudo}#{repo.
|
97
|
+
commands << "#{repo.dapp.rm_bin} -rf \"#{to}\""
|
98
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
99
|
+
commands << "#{sudo}#{repo.dapp.tar_bin} -xf #{archive_file(stage, *dev_patch_stage_commits(stage))} -C \"#{File.dirname(to)}\""
|
100
100
|
else
|
101
101
|
raise
|
102
102
|
end
|
@@ -105,11 +105,11 @@ module Dapp
|
|
105
105
|
if patch_any_changes?(stage)
|
106
106
|
case archive_type
|
107
107
|
when :directory
|
108
|
-
commands << "#{repo.
|
109
|
-
commands << "#{sudo}#{repo.
|
108
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{to}\""
|
109
|
+
commands << "#{sudo}#{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{to}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
|
110
110
|
when :file
|
111
|
-
commands << "#{repo.
|
112
|
-
commands << "#{sudo}#{repo.
|
111
|
+
commands << "#{repo.dapp.install_bin} #{credentials.join(' ')} -d \"#{File.dirname(to)}\""
|
112
|
+
commands << "#{sudo}#{repo.dapp.git_bin} apply --whitespace=nowarn --directory=\"#{File.dirname(to)}\" --unsafe-paths #{patch_file(stage, *patch_stage_commits(stage))}"
|
113
113
|
else
|
114
114
|
raise
|
115
115
|
end
|
@@ -129,9 +129,9 @@ module Dapp
|
|
129
129
|
@stage_dependencies_checksums ||= {}
|
130
130
|
@stage_dependencies_checksums[stage_dependencies_key] ||= begin
|
131
131
|
if (entries = repo_entries(commit, paths: paths)).empty?
|
132
|
-
repo.
|
133
|
-
|
134
|
-
|
132
|
+
repo.dapp.log_warning(desc: { code: :stage_dependencies_not_found,
|
133
|
+
data: { repo: repo.respond_to?(:url) ? repo.url : 'local',
|
134
|
+
dependencies: stage_dependencies.join(', ') } })
|
135
135
|
end
|
136
136
|
|
137
137
|
entries
|
@@ -203,7 +203,7 @@ module Dapp
|
|
203
203
|
attr_reader :stages_dependencies
|
204
204
|
|
205
205
|
def sudo
|
206
|
-
repo.
|
206
|
+
repo.dapp.sudo_command(owner: owner, group: group)
|
207
207
|
end
|
208
208
|
|
209
209
|
def credentials
|
@@ -211,7 +211,7 @@ module Dapp
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def archive_file(stage, commit)
|
214
|
-
if repo.
|
214
|
+
if repo.dapp.options[:use_system_tar]
|
215
215
|
archive_file_with_system_tar(stage, commit)
|
216
216
|
else
|
217
217
|
archive_file_with_tar_writer(stage, commit)
|
@@ -249,7 +249,7 @@ module Dapp
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
-
repo.
|
252
|
+
repo.dapp.shellout!("tar -C #{repo.dimg.tmp_path(relative_archive_file_path)} -cf #{archive_path} .")
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -3,14 +3,33 @@ module Dapp
|
|
3
3
|
module GitRepo
|
4
4
|
# Base class for any Git repo (remote, gitkeeper, etc)
|
5
5
|
class Base
|
6
|
-
attr_reader :dimg
|
7
6
|
attr_reader :name
|
8
7
|
|
9
|
-
def initialize(
|
10
|
-
@
|
8
|
+
def initialize(manager, name)
|
9
|
+
@manager = manager
|
11
10
|
@name = name
|
12
11
|
end
|
13
12
|
|
13
|
+
def dapp
|
14
|
+
@dapp ||= begin
|
15
|
+
if manager.is_a? ::Dapp::Dapp
|
16
|
+
manager
|
17
|
+
else
|
18
|
+
dimg.dapp
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def dimg
|
24
|
+
@dimg ||= begin
|
25
|
+
if manager.is_a? ::Dapp::Dimg::Dimg
|
26
|
+
manager
|
27
|
+
else
|
28
|
+
raise
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
14
33
|
def exclude_paths
|
15
34
|
[]
|
16
35
|
end
|
@@ -92,6 +111,8 @@ module Dapp
|
|
92
111
|
|
93
112
|
protected
|
94
113
|
|
114
|
+
attr_reader :manager
|
115
|
+
|
95
116
|
def git(**kwargs)
|
96
117
|
@git ||= Rugged::Repository.new(path.to_s, **kwargs)
|
97
118
|
end
|
@@ -2,12 +2,12 @@ module Dapp
|
|
2
2
|
module Dimg
|
3
3
|
module GitRepo
|
4
4
|
class Own < Base
|
5
|
-
def initialize(
|
6
|
-
super(
|
5
|
+
def initialize(manager)
|
6
|
+
super(manager, 'own')
|
7
7
|
end
|
8
8
|
|
9
9
|
def exclude_paths
|
10
|
-
|
10
|
+
dapp.local_git_artifact_exclude_paths
|
11
11
|
end
|
12
12
|
|
13
13
|
def workdir_path
|
@@ -15,7 +15,7 @@ module Dapp
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def path
|
18
|
-
@path ||= Pathname(Rugged::Repository.discover(
|
18
|
+
@path ||= Pathname(Rugged::Repository.discover(dapp.path.to_s).path)
|
19
19
|
rescue Rugged::RepositoryError => _e
|
20
20
|
raise Error::Rugged, code: :local_git_repository_does_not_exist
|
21
21
|
end
|
@@ -9,7 +9,7 @@ module Dapp
|
|
9
9
|
|
10
10
|
@url = url
|
11
11
|
|
12
|
-
|
12
|
+
dapp.log_secondary_process(dapp.t(code: 'process.git_artifact_clone', data: { url: url }), short: true) do
|
13
13
|
begin
|
14
14
|
if [:https, :ssh].include?(protocol) && !Rugged.features.include?(protocol)
|
15
15
|
raise Error::Rugged, code: :rugged_protocol_not_supported, data: { url: url, protocol: protocol }
|
@@ -38,10 +38,10 @@ module Dapp
|
|
38
38
|
|
39
39
|
def fetch!(branch = nil)
|
40
40
|
branch ||= self.branch
|
41
|
-
|
41
|
+
dapp.log_secondary_process(dapp.t(code: 'process.git_artifact_fetch', data: { url: url }), short: true) do
|
42
42
|
git.fetch('origin', [branch], credentials: _rugged_credentials)
|
43
43
|
raise Error::Rugged, code: :branch_not_exist_in_remote_git_repository, data: { branch: branch, url: url } unless branch_exist?(branch)
|
44
|
-
end unless dimg.ignore_git_fetch ||
|
44
|
+
end unless dimg.ignore_git_fetch || dapp.dry_run?
|
45
45
|
end
|
46
46
|
|
47
47
|
def branch_exist?(name)
|
@@ -12,9 +12,31 @@ BANNER
|
|
12
12
|
long: '--namespace NAME',
|
13
13
|
default: nil
|
14
14
|
|
15
|
-
option :
|
16
|
-
long: '--
|
17
|
-
|
15
|
+
option :tag,
|
16
|
+
long: '--tag TAG',
|
17
|
+
description: 'Custom tag',
|
18
|
+
default: [],
|
19
|
+
proc: proc { |v| composite_options(:tags) << v }
|
20
|
+
|
21
|
+
option :tag_branch,
|
22
|
+
long: '--tag-branch',
|
23
|
+
description: 'Tag by git branch',
|
24
|
+
boolean: true
|
25
|
+
|
26
|
+
option :tag_build_id,
|
27
|
+
long: '--tag-build-id',
|
28
|
+
description: 'Tag by CI build id',
|
29
|
+
boolean: true
|
30
|
+
|
31
|
+
option :tag_ci,
|
32
|
+
long: '--tag-ci',
|
33
|
+
description: 'Tag by CI branch and tag',
|
34
|
+
boolean: true
|
35
|
+
|
36
|
+
option :tag_commit,
|
37
|
+
long: '--tag-commit',
|
38
|
+
description: 'Tag by git commit',
|
39
|
+
boolean: true
|
18
40
|
|
19
41
|
option :tmp_dir_prefix,
|
20
42
|
long: '--tmp-dir-prefix PREFIX',
|
@@ -10,27 +10,49 @@ Options:
|
|
10
10
|
BANNER
|
11
11
|
|
12
12
|
option :namespace,
|
13
|
-
|
14
|
-
|
13
|
+
long: '--namespace NAME',
|
14
|
+
default: nil
|
15
15
|
|
16
|
-
option :
|
17
|
-
|
18
|
-
|
16
|
+
option :tag,
|
17
|
+
long: '--tag TAG',
|
18
|
+
description: 'Custom tag',
|
19
|
+
default: [],
|
20
|
+
proc: proc { |v| composite_options(:tags) << v }
|
21
|
+
|
22
|
+
option :tag_branch,
|
23
|
+
long: '--tag-branch',
|
24
|
+
description: 'Tag by git branch',
|
25
|
+
boolean: true
|
26
|
+
|
27
|
+
option :tag_build_id,
|
28
|
+
long: '--tag-build-id',
|
29
|
+
description: 'Tag by CI build id',
|
30
|
+
boolean: true
|
31
|
+
|
32
|
+
option :tag_ci,
|
33
|
+
long: '--tag-ci',
|
34
|
+
description: 'Tag by CI branch and tag',
|
35
|
+
boolean: true
|
36
|
+
|
37
|
+
option :tag_commit,
|
38
|
+
long: '--tag-commit',
|
39
|
+
description: 'Tag by git commit',
|
40
|
+
boolean: true
|
19
41
|
|
20
42
|
option :helm_set_options,
|
21
|
-
|
22
|
-
|
23
|
-
|
43
|
+
long: '--set STRING_ARRAY',
|
44
|
+
default: [],
|
45
|
+
proc: proc { |v| composite_options(:helm_set) << v }
|
24
46
|
|
25
47
|
option :helm_values_options,
|
26
|
-
|
27
|
-
|
28
|
-
|
48
|
+
long: '--values FILE_PATH',
|
49
|
+
default: [],
|
50
|
+
proc: proc { |v| composite_options(:helm_values) << v }
|
29
51
|
|
30
52
|
option :helm_secret_values_options,
|
31
|
-
|
32
|
-
|
33
|
-
|
53
|
+
long: '--secret-values FILE_PATH',
|
54
|
+
default: [],
|
55
|
+
proc: proc { |v| composite_options(:helm_secret_values) << v }
|
34
56
|
|
35
57
|
def run(argv = ARGV)
|
36
58
|
self.class.parse_options(self, argv)
|
@@ -12,9 +12,31 @@ BANNER
|
|
12
12
|
long: '--namespace NAME',
|
13
13
|
default: nil
|
14
14
|
|
15
|
-
option :
|
16
|
-
long: '--
|
17
|
-
|
15
|
+
option :tag,
|
16
|
+
long: '--tag TAG',
|
17
|
+
description: 'Custom tag',
|
18
|
+
default: [],
|
19
|
+
proc: proc { |v| composite_options(:tags) << v }
|
20
|
+
|
21
|
+
option :tag_branch,
|
22
|
+
long: '--tag-branch',
|
23
|
+
description: 'Tag by git branch',
|
24
|
+
boolean: true
|
25
|
+
|
26
|
+
option :tag_build_id,
|
27
|
+
long: '--tag-build-id',
|
28
|
+
description: 'Tag by CI build id',
|
29
|
+
boolean: true
|
30
|
+
|
31
|
+
option :tag_ci,
|
32
|
+
long: '--tag-ci',
|
33
|
+
description: 'Tag by CI branch and tag',
|
34
|
+
boolean: true
|
35
|
+
|
36
|
+
option :tag_commit,
|
37
|
+
long: '--tag-commit',
|
38
|
+
description: 'Tag by git commit',
|
39
|
+
boolean: true
|
18
40
|
|
19
41
|
option :tmp_dir_prefix,
|
20
42
|
long: '--tmp-dir-prefix PREFIX',
|
@@ -9,9 +9,13 @@ module Dapp
|
|
9
9
|
kube_check_helm_chart!
|
10
10
|
|
11
11
|
repo = option_repo
|
12
|
-
|
12
|
+
tag = begin
|
13
|
+
raise Error::Command, code: :expected_only_one_tag,
|
14
|
+
data: { tags: option_tags.join(', ') } if option_tags.count > 1
|
15
|
+
option_tags.first
|
16
|
+
end
|
13
17
|
validate_repo_name!(repo)
|
14
|
-
validate_tag_name!(
|
18
|
+
validate_tag_name!(tag)
|
15
19
|
|
16
20
|
with_kube_tmp_chart_dir do
|
17
21
|
kube_copy_chart
|
@@ -22,7 +26,7 @@ module Dapp
|
|
22
26
|
self,
|
23
27
|
name: kube_release_name,
|
24
28
|
repo: repo,
|
25
|
-
|
29
|
+
docker_tag: tag,
|
26
30
|
namespace: kube_namespace,
|
27
31
|
chart_path: kube_chart_path_for_helm,
|
28
32
|
set: self.options[:helm_set_options],
|
@@ -92,10 +96,10 @@ module Dapp
|
|
92
96
|
{{- if (ge (len (index .)) 2) -}}
|
93
97
|
{{- $name := index . 0 -}}
|
94
98
|
{{- $context := index . 1 -}}
|
95
|
-
{{- printf "%v:%v
|
99
|
+
{{- printf "%v/%v:%v" $context.Values.global.dapp.repo $name $context.Values.global.dapp.docker_tag -}}
|
96
100
|
{{- else -}}
|
97
101
|
{{- $context := index . 0 -}}
|
98
|
-
{{- printf "%v:%v" $context.Values.global.dapp.repo $context.Values.global.dapp.
|
102
|
+
{{- printf "%v:%v" $context.Values.global.dapp.repo $context.Values.global.dapp.docker_tag -}}
|
99
103
|
{{- end -}}
|
100
104
|
{{- end -}}
|
101
105
|
|
@@ -31,7 +31,7 @@ module Dapp
|
|
31
31
|
kube_check_helm_chart!
|
32
32
|
|
33
33
|
repo = option_repo
|
34
|
-
|
34
|
+
docker_tag = options[:docker_tag]
|
35
35
|
|
36
36
|
with_kube_tmp_lint_chart_dir do
|
37
37
|
kube_copy_chart
|
@@ -61,8 +61,8 @@ module Dapp
|
|
61
61
|
all_values['global'] = {
|
62
62
|
'namespace' => kube_namespace,
|
63
63
|
'dapp' => {
|
64
|
-
'repo' =>
|
65
|
-
'
|
64
|
+
'repo' => repo,
|
65
|
+
'docker_tag' => docker_tag
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
@@ -7,7 +7,7 @@ module Dapp
|
|
7
7
|
|
8
8
|
attr_reader :name
|
9
9
|
attr_reader :repo
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :docker_tag
|
11
11
|
attr_reader :namespace
|
12
12
|
attr_reader :chart_path
|
13
13
|
attr_reader :set
|
@@ -15,13 +15,13 @@ module Dapp
|
|
15
15
|
attr_reader :deploy_timeout
|
16
16
|
|
17
17
|
def initialize(dapp,
|
18
|
-
name:, repo:,
|
18
|
+
name:, repo:, docker_tag:, namespace:, chart_path:,
|
19
19
|
set: [], values: [], deploy_timeout: nil)
|
20
20
|
@dapp = dapp
|
21
21
|
|
22
22
|
@name = name
|
23
23
|
@repo = repo
|
24
|
-
@
|
24
|
+
@docker_tag = docker_tag
|
25
25
|
@namespace = namespace
|
26
26
|
@chart_path = chart_path
|
27
27
|
@set = set
|
@@ -119,7 +119,7 @@ module Dapp
|
|
119
119
|
[].tap do |options|
|
120
120
|
options.concat(set.map { |opt| "--set #{opt}" })
|
121
121
|
options << "--set global.dapp.repo=#{repo}"
|
122
|
-
options << "--set global.dapp.
|
122
|
+
options << "--set global.dapp.docker_tag=#{docker_tag}"
|
123
123
|
options << "--set global.namespace=#{namespace}"
|
124
124
|
end
|
125
125
|
end
|
data/lib/dapp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Stolyarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -444,6 +444,7 @@ files:
|
|
444
444
|
- lib/dapp/dapp/logging/i18n.rb
|
445
445
|
- lib/dapp/dapp/logging/paint.rb
|
446
446
|
- lib/dapp/dapp/logging/process.rb
|
447
|
+
- lib/dapp/dapp/option_tags.rb
|
447
448
|
- lib/dapp/dapp/shellout/base.rb
|
448
449
|
- lib/dapp/dapp/shellout/streaming.rb
|
449
450
|
- lib/dapp/dapp/ssh_agent.rb
|
@@ -595,12 +596,12 @@ files:
|
|
595
596
|
- lib/dapp/dimg/dimg/git_artifact.rb
|
596
597
|
- lib/dapp/dimg/dimg/path.rb
|
597
598
|
- lib/dapp/dimg/dimg/stages.rb
|
598
|
-
- lib/dapp/dimg/dimg/tags.rb
|
599
599
|
- lib/dapp/dimg/docker_registry.rb
|
600
600
|
- lib/dapp/dimg/docker_registry/base.rb
|
601
601
|
- lib/dapp/dimg/docker_registry/base/authorization.rb
|
602
602
|
- lib/dapp/dimg/docker_registry/base/request.rb
|
603
603
|
- lib/dapp/dimg/docker_registry/default.rb
|
604
|
+
- lib/dapp/dimg/docker_registry/dimg.rb
|
604
605
|
- lib/dapp/dimg/error/base.rb
|
605
606
|
- lib/dapp/dimg/error/build.rb
|
606
607
|
- lib/dapp/dimg/error/chef.rb
|
data/lib/dapp/dimg/dimg/tags.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Dimg
|
3
|
-
class Dimg
|
4
|
-
module Tags
|
5
|
-
protected
|
6
|
-
|
7
|
-
def git_repo
|
8
|
-
@git_repo ||= GitRepo::Own.new(self)
|
9
|
-
end
|
10
|
-
|
11
|
-
def tags
|
12
|
-
tags = simple_tags + branch_tags + commit_tags + build_tags + ci_tags
|
13
|
-
tags << :latest if tags.empty?
|
14
|
-
tags
|
15
|
-
end
|
16
|
-
|
17
|
-
def simple_tags
|
18
|
-
dapp.options[:tag]
|
19
|
-
end
|
20
|
-
|
21
|
-
def branch_tags
|
22
|
-
return [] unless dapp.options[:tag_branch]
|
23
|
-
raise Error::Dimg, code: :git_branch_without_name if (branch = git_repo.branch) == 'HEAD'
|
24
|
-
[branch]
|
25
|
-
end
|
26
|
-
|
27
|
-
def commit_tags
|
28
|
-
return [] unless dapp.options[:tag_commit]
|
29
|
-
commit = git_repo.latest_commit
|
30
|
-
[commit]
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_tags
|
34
|
-
return [] unless dapp.options[:tag_build_id]
|
35
|
-
|
36
|
-
if ENV['GITLAB_CI']
|
37
|
-
build_id = ENV['CI_BUILD_ID']
|
38
|
-
elsif ENV['TRAVIS']
|
39
|
-
build_id = ENV['TRAVIS_BUILD_NUMBER']
|
40
|
-
else
|
41
|
-
raise Error::Dimg, code: :ci_environment_required
|
42
|
-
end
|
43
|
-
|
44
|
-
[build_id]
|
45
|
-
end
|
46
|
-
|
47
|
-
def ci_tags
|
48
|
-
return [] unless dapp.options[:tag_ci]
|
49
|
-
|
50
|
-
if ENV['GITLAB_CI']
|
51
|
-
branch = ENV['CI_BUILD_REF_NAME']
|
52
|
-
tag = ENV['CI_BUILD_TAG']
|
53
|
-
elsif ENV['TRAVIS']
|
54
|
-
branch = ENV['TRAVIS_BRANCH']
|
55
|
-
tag = ENV['TRAVIS_TAG']
|
56
|
-
else
|
57
|
-
raise Error::Dimg, code: :ci_environment_required
|
58
|
-
end
|
59
|
-
|
60
|
-
[branch, tag].compact
|
61
|
-
end
|
62
|
-
end # Tags
|
63
|
-
end # Mod
|
64
|
-
end # Dimg
|
65
|
-
end # Dapp
|