dapp 0.34.7 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dapp +1 -23
- data/config/en/net_status.yml +1 -5
- data/lib/dapp.rb +0 -4
- data/lib/dapp/dapp.rb +3 -2
- data/lib/dapp/dapp/command/common.rb +1 -1
- data/lib/dapp/dapp/ruby2go.rb +4 -0
- data/lib/dapp/dimg/build/stage/base.rb +1 -0
- data/lib/dapp/dimg/cli/command/dimg/cleanup_repo.rb +1 -1
- data/lib/dapp/dimg/cli/command/dimg/flush_repo.rb +1 -1
- data/lib/dapp/dimg/cli/command/dimg/stages/cleanup_local.rb +1 -1
- data/lib/dapp/dimg/cli/command/dimg/stages/flush_repo.rb +1 -1
- data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +8 -14
- data/lib/dapp/dimg/dapp/command/stages/cleanup_repo.rb +5 -5
- data/lib/dapp/dimg/dapp/command/stages/common.rb +13 -10
- data/lib/dapp/dimg/dimg.rb +1 -1
- data/lib/dapp/dimg/docker_registry.rb +2 -19
- data/lib/dapp/dimg/docker_registry/base.rb +22 -80
- data/lib/dapp/dimg/docker_registry/dimg.rb +29 -23
- data/lib/dapp/kube/helm/values.rb +1 -1
- data/lib/dapp/kube/kubernetes/manager/deployment.rb +18 -30
- data/lib/dapp/version.rb +1 -1
- metadata +3 -7
- data/lib/dapp/dimg/docker_registry/base/authorization.rb +0 -69
- data/lib/dapp/dimg/docker_registry/base/request.rb +0 -34
- data/lib/dapp/dimg/docker_registry/default.rb +0 -18
- data/lib/dapp/dimg/docker_registry/error.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c94384729263dd6beae2c0cfcbd75f09010d43f334726ad53f561e70f43e93
|
4
|
+
data.tar.gz: ea069cf6302db1aaf1e90291299f9dbf1887f06f091afd4a7bdf9beaaba7be25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f26d814a0f747fd4a40b7dc17d63896bfaf15dcd748a8bd1c7a467dde708bedc43726ab120cb8027e6f7ac1b832eae354c6ede5d9010bc402922981d5fe190
|
7
|
+
data.tar.gz: 89517f7d50bef08d1d62f9f6fdd73de52068a7097f770326344f4b1b956a42d1517f482c8cb6d0591c465e86c043ee97edcfeaac9dcfc9be6641564d56c78a09
|
data/bin/dapp
CHANGED
@@ -74,29 +74,7 @@ set_gitlab_cancel_handler if ENV["GITLAB_CI"]
|
|
74
74
|
begin
|
75
75
|
begin
|
76
76
|
begin
|
77
|
-
|
78
|
-
Dapp::CLI.new.run
|
79
|
-
ensure
|
80
|
-
if Time.now.to_date < Date.parse("2019-11-01")
|
81
|
-
STDERR.puts
|
82
|
-
STDERR.puts ::Paint["###################################################################", :red, :bold]
|
83
|
-
STDERR.puts ::Paint["### DEPRECATION WARNING! ###", :red, :bold]
|
84
|
-
STDERR.puts ::Paint["### Dapp will be deprecated for use starting with 01.11.2019! ###", :red, :bold]
|
85
|
-
STDERR.puts ::Paint["### Please port your project to werf: ###", :red, :bold]
|
86
|
-
STDERR.puts ::Paint["### https://werf.io ###", :red, :bold]
|
87
|
-
STDERR.puts ::Paint["###################################################################", :red, :bold]
|
88
|
-
STDERR.puts
|
89
|
-
else
|
90
|
-
STDERR.puts
|
91
|
-
STDERR.puts ::Paint["######################################################################", :red, :bold]
|
92
|
-
STDERR.puts ::Paint["### DEPRECATION WARNING! ###", :red, :bold]
|
93
|
-
STDERR.puts ::Paint["### Dapp is deprecated for use and will not receive any support! ###", :red, :bold]
|
94
|
-
STDERR.puts ::Paint["### Please port your project to werf: ###", :red, :bold]
|
95
|
-
STDERR.puts ::Paint["### https://werf.io ###", :red, :bold]
|
96
|
-
STDERR.puts ::Paint["######################################################################", :red, :bold]
|
97
|
-
STDERR.puts
|
98
|
-
end
|
99
|
-
end
|
77
|
+
Dapp::CLI.new.run
|
100
78
|
rescue Dapp::Error::Base => e
|
101
79
|
unless (message = Dapp::Helper::NetStatus.before_error_message(e)).empty?
|
102
80
|
$stderr.puts(message)
|
data/config/en/net_status.yml
CHANGED
@@ -122,11 +122,7 @@ en:
|
|
122
122
|
builder_cookbook_not_found: "Dapp cookbook directory not found at %{path}"
|
123
123
|
berksfile_absolute_path_forbidden: "Absolute paths in Berksfile are not allowed (cookbook `%{cookbook}`, path: `%{path}`)"
|
124
124
|
registry:
|
125
|
-
|
126
|
-
page_not_found: "Registry `%{registry}`: page `%{url}` not found!"
|
127
|
-
method_not_allowed: "Registry `%{registry}`: method `%{method}` not allowed (`%{url}`)!"
|
128
|
-
user_not_authorized: 'Registry `%{registry}`: user not authorized!'
|
129
|
-
registry_not_available: 'Registry `%{registry}`: not available!'
|
125
|
+
ruby2go_docker_registry_command_failed_unexpected_error: 'ruby2go_docker_registry command `%{command}` failed: `%{message}`!'
|
130
126
|
rugged:
|
131
127
|
git_repository_reference_error: "Git repo `%{name}`: %{message}!"
|
132
128
|
rugged_remote_error: "Remote git repo `%{url}`: `%{message}`!"
|
data/lib/dapp.rb
CHANGED
@@ -266,12 +266,8 @@ require 'dapp/dimg/dapp/dimg'
|
|
266
266
|
require 'dapp/dimg/dapp/config_artifact_group'
|
267
267
|
require 'dapp/dimg/dapp/dapp'
|
268
268
|
require 'dapp/dimg/docker_registry'
|
269
|
-
require 'dapp/dimg/docker_registry/error'
|
270
|
-
require 'dapp/dimg/docker_registry/base/request'
|
271
|
-
require 'dapp/dimg/docker_registry/base/authorization'
|
272
269
|
require 'dapp/dimg/docker_registry/base'
|
273
270
|
require 'dapp/dimg/docker_registry/dimg'
|
274
|
-
require 'dapp/dimg/docker_registry/default'
|
275
271
|
require 'dapp/dimg/lock/base'
|
276
272
|
require 'dapp/dimg/lock/file'
|
277
273
|
require 'dapp/dimg/filelock'
|
data/lib/dapp/dapp.rb
CHANGED
@@ -237,9 +237,10 @@ module Dapp
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def docker_credentials
|
240
|
-
if options
|
240
|
+
if options[:registry_username] && options[:registry_password]
|
241
241
|
[options[:registry_username], options[:registry_password]]
|
242
|
-
elsif ENV.key?('
|
242
|
+
elsif ENV.key?('DAPP_DOCKER_CONFIG')
|
243
|
+
elsif !ENV.key?('DAPP_IGNORE_CI_DOCKER_AUTOLOGIN') && ENV.key?('CI_JOB_TOKEN')
|
243
244
|
['gitlab-ci-token', ENV['CI_JOB_TOKEN']]
|
244
245
|
end
|
245
246
|
end
|
data/lib/dapp/dapp/ruby2go.rb
CHANGED
@@ -113,6 +113,7 @@ module Dapp
|
|
113
113
|
image.add_service_change_label dapp: dimg.stage_dapp_label
|
114
114
|
image.add_service_change_label 'dapp-version'.to_sym => ::Dapp::VERSION
|
115
115
|
image.add_service_change_label 'dapp-cache-version'.to_sym => ::Dapp::BUILD_CACHE_VERSION
|
116
|
+
image.add_service_change_label 'dapp-dimg'.to_sym => false
|
116
117
|
image.add_service_change_label 'dapp-dev-mode'.to_sym => true if dimg.dev_mode?
|
117
118
|
|
118
119
|
if dimg.dapp.ssh_auth_sock
|
@@ -39,7 +39,7 @@ BANNER
|
|
39
39
|
def run(argv = ARGV)
|
40
40
|
self.class.parse_options(self, argv)
|
41
41
|
repo = self.class.required_argument(self, 'repo')
|
42
|
-
run_dapp_command(run_method, options: cli_options(dimgs_patterns: cli_arguments, repo: repo, verbose: true))
|
42
|
+
run_dapp_command(run_method, options: cli_options(dimgs_patterns: cli_arguments, repo: repo, verbose: true), try_host_docker_login: true)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -28,7 +28,7 @@ BANNER
|
|
28
28
|
def run(argv = ARGV)
|
29
29
|
self.class.parse_options(self, argv)
|
30
30
|
repo = self.class.required_argument(self, 'repo')
|
31
|
-
run_dapp_command(run_method, options: cli_options(dimgs_patterns: cli_arguments, repo: repo, verbose: true))
|
31
|
+
run_dapp_command(run_method, options: cli_options(dimgs_patterns: cli_arguments, repo: repo, verbose: true), try_host_docker_login: true)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -31,7 +31,7 @@ BANNER
|
|
31
31
|
def run(argv = ARGV)
|
32
32
|
self.class.parse_options(self, argv)
|
33
33
|
repository = repo
|
34
|
-
run_dapp_command(run_method, options: cli_options(repo: repository))
|
34
|
+
run_dapp_command(run_method, options: cli_options(repo: repository), try_host_docker_login: true)
|
35
35
|
end
|
36
36
|
|
37
37
|
def repo
|
@@ -19,7 +19,7 @@ BANNER
|
|
19
19
|
def run(argv = ARGV)
|
20
20
|
self.class.parse_options(self, argv)
|
21
21
|
repo = self.class.required_argument(self, 'repo')
|
22
|
-
run_dapp_command(:stages_flush_repo, options: cli_options(repo: repo))
|
22
|
+
run_dapp_command(:stages_flush_repo, options: cli_options(repo: repo), try_host_docker_login: true)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -225,65 +225,59 @@ module Dapp
|
|
225
225
|
# pod items[] spec containers[] image
|
226
226
|
def pod_images(client)
|
227
227
|
client.pod_list['items'].map do |item|
|
228
|
-
|
228
|
+
item['spec']['containers'].map{ |cont| cont['image'] }
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
232
|
# cronjob items[] spec jobTemplate spec template spec containers[] image
|
233
233
|
def cronjob_images(client)
|
234
234
|
client.cronjob_list['items'].map do |item|
|
235
|
-
|
235
|
+
item['spec']['jobTemplate']['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
239
|
# daemonsets items[] spec template spec containers[] image
|
240
240
|
def daemonset_images(client)
|
241
241
|
client.daemonset_list['items'].map do |item|
|
242
|
-
|
242
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
246
|
# deployment items[] spec template spec containers[] image
|
247
247
|
def deployment_images(client)
|
248
248
|
client.deployment_list['items'].map do |item|
|
249
|
-
|
249
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
253
|
# job items[] spec template spec containers[] image
|
254
254
|
def job_images(client)
|
255
255
|
client.job_list['items'].map do |item|
|
256
|
-
|
256
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
260
|
# replicasets items[] spec template spec containers[] image
|
261
261
|
def replicaset_images(client)
|
262
262
|
client.replicaset_list['items'].map do |item|
|
263
|
-
|
263
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
267
|
# replicasets items[] spec template spec containers[] image
|
268
268
|
def statefulset_images(client)
|
269
269
|
client.statefulset_list['items'].map do |item|
|
270
|
-
|
270
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
274
274
|
# replicationcontroller items[] spec template spec containers[] image
|
275
275
|
def replicationcontroller_images(client)
|
276
276
|
client.replicationcontroller_list['items'].map do |item|
|
277
|
-
|
277
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
def images_from_pod_spec(pod_spec)
|
282
|
-
containers = Array(pod_spec['spec']['containers'])
|
283
|
-
initContainers = Array(pod_spec['spec']['initContainers'])
|
284
|
-
(containers + initContainers).map { |cont| cont['image'] }
|
285
|
-
end
|
286
|
-
|
287
281
|
def without_kube?
|
288
282
|
!!options[:without_kube]
|
289
283
|
end
|
@@ -55,11 +55,11 @@ module Dapp
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def repo_image_dapp_artifacts_labels(registry, repo_image)
|
58
|
-
select_dapp_artifacts_ids(registry.
|
58
|
+
select_dapp_artifacts_ids(registry.image_config(repo_image[:tag], repo_image[:dimg])["config"]["Labels"])
|
59
59
|
end
|
60
60
|
|
61
61
|
def repo_image_dapp_cache_version_label(registry, repo_image)
|
62
|
-
registry.
|
62
|
+
registry.image_config(repo_image[:tag], repo_image[:dimg])["config"]["Labels"]['dapp-cache-version']
|
63
63
|
end
|
64
64
|
|
65
65
|
def repo_image_by_id(repo_image_id, repo_images)
|
@@ -82,9 +82,9 @@ module Dapp
|
|
82
82
|
def repo_detailed_dimgstage_images(registry)
|
83
83
|
@repo_dapp_dimgstage_images_detailed ||= begin
|
84
84
|
repo_dimgstages_images(registry).each do |dimgstage|
|
85
|
-
|
86
|
-
dimgstage[:parent] =
|
87
|
-
dimgstage[:labels] =
|
85
|
+
image_config = registry.image_config(dimgstage[:tag], nil)
|
86
|
+
dimgstage[:parent] = image_config["container_config"]["Image"]
|
87
|
+
dimgstage[:labels] = image_config["config"]["Labels"]
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -9,13 +9,14 @@ module Dapp
|
|
9
9
|
def repo_detailed_dimgs_images(registry)
|
10
10
|
repo_dimgs_images(registry).select do |dimg|
|
11
11
|
begin
|
12
|
-
|
13
|
-
dimg[:created_at] = Time.parse(
|
14
|
-
dimg[:parent] =
|
15
|
-
dimg[:labels] =
|
12
|
+
image_config = registry.image_config(dimg[:tag], dimg[:dimg])
|
13
|
+
dimg[:created_at] = Time.parse(image_config["created"]).to_i
|
14
|
+
dimg[:parent] = image_config["container_config"]["Image"]
|
15
|
+
dimg[:labels] = image_config["config"]["Labels"]
|
16
16
|
dimg[:labels]['dapp'] == name
|
17
|
-
rescue ::Dapp::Dimg::
|
18
|
-
|
17
|
+
rescue ::Dapp::Dimg::Error::Registry => e
|
18
|
+
raise unless e.net_status[:data][:message].include?("MANIFEST_UNKNOWN")
|
19
|
+
log_warning "WARNING: Ignore dimg `#{dimg[:dimg]}` tag `#{dimg[:tag]}`: got manifest-invalid-error from docker registry: #{e.net_status[:data][:message]}"
|
19
20
|
false
|
20
21
|
end
|
21
22
|
end
|
@@ -52,8 +53,9 @@ module Dapp
|
|
52
53
|
end
|
53
54
|
|
54
55
|
return { dimg: dimg_name, tag: tag, id: id }
|
55
|
-
rescue ::Dapp::Dimg::
|
56
|
-
|
56
|
+
rescue ::Dapp::Dimg::Error::Registry => e
|
57
|
+
raise unless e.net_status[:data][:message].include?("MANIFEST_UNKNOWN")
|
58
|
+
log_warning "WARNING: Ignore dimg `#{dimg_name}` tag `#{tag}`: got not-found-error from docker registry on get-image-manifest request: #{e.net_status[:data][:message]}"
|
57
59
|
return nil
|
58
60
|
end
|
59
61
|
end
|
@@ -63,8 +65,9 @@ module Dapp
|
|
63
65
|
unless dry_run?
|
64
66
|
begin
|
65
67
|
registry.image_delete(repo_image[:tag], repo_image[:dimg])
|
66
|
-
rescue ::Dapp::Dimg::
|
67
|
-
|
68
|
+
rescue ::Dapp::Dimg::Error::Registry => e
|
69
|
+
raise unless e.net_status[:data][:message].include?("MANIFEST_UNKNOWN")
|
70
|
+
log_warning "WARNING: Ignore dimg `#{repo_image[:dimg]}` tag `#{repo_image[:tag]}`: got not-found-error from docker registry on image-delete request: #{e.net_status[:data][:message]}"
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
data/lib/dapp/dimg/dimg.rb
CHANGED
@@ -126,7 +126,7 @@ module Dapp
|
|
126
126
|
|
127
127
|
def tag_should_not_be_pushed?(tag)
|
128
128
|
registry_tags.include?(tag) && begin
|
129
|
-
registry_tag_parent = registry.
|
129
|
+
registry_tag_parent = registry.image_parent_id(tag, name)
|
130
130
|
registry_tag_parent == last_stage.image.built_id
|
131
131
|
end
|
132
132
|
end
|
@@ -1,20 +1,8 @@
|
|
1
1
|
module Dapp
|
2
2
|
module Dimg
|
3
3
|
module DockerRegistry
|
4
|
-
def self.new(repo)
|
5
|
-
|
6
|
-
expected_hostname = Regexp.last_match(:hostname)
|
7
|
-
expected_repo_suffix = Regexp.last_match(:repo_suffix)
|
8
|
-
|
9
|
-
if expected_hostname
|
10
|
-
%w(https http).each do |protocol|
|
11
|
-
expected_hostname_url = [protocol, expected_hostname].join('://')
|
12
|
-
return Dimg.new(repo, expected_hostname_url, expected_repo_suffix) if hostname_exist?(expected_hostname_url)
|
13
|
-
end
|
14
|
-
raise ::Dapp::Dimg::Error::Registry, code: :registry_not_available, data: { registry: repo }
|
15
|
-
else
|
16
|
-
Default.new(repo, expected_repo_suffix)
|
17
|
-
end
|
4
|
+
def self.new(dapp, repo)
|
5
|
+
Dimg.new(dapp, repo)
|
18
6
|
end
|
19
7
|
|
20
8
|
def self.repo_name_format
|
@@ -26,11 +14,6 @@ module Dapp
|
|
26
14
|
def self.repo_name?(name)
|
27
15
|
!(/^#{repo_name_format}$/ =~ name).nil?
|
28
16
|
end
|
29
|
-
|
30
|
-
def self.hostname_exist?(url)
|
31
|
-
return false unless url
|
32
|
-
Base.url_available?(url)
|
33
|
-
end
|
34
17
|
end # DockerRegistry
|
35
18
|
end # Dimg
|
36
19
|
end # Dapp
|
@@ -2,109 +2,51 @@ module Dapp
|
|
2
2
|
module Dimg
|
3
3
|
module DockerRegistry
|
4
4
|
class Base
|
5
|
-
|
6
|
-
|
5
|
+
attr_accessor :dapp
|
6
|
+
attr_accessor :repository
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_accessor :hostname_url
|
12
|
-
attr_accessor :repo_suffix
|
13
|
-
|
14
|
-
def initialize(repo, hostname_url, repo_suffix)
|
15
|
-
self.repo = repo
|
16
|
-
self.hostname_url = hostname_url
|
17
|
-
self.repo_suffix = repo_suffix
|
18
|
-
end
|
19
|
-
|
20
|
-
def tags
|
21
|
-
api_request(repo_suffix, 'tags/list')['tags'] || []
|
8
|
+
def initialize(dapp, repository)
|
9
|
+
self.dapp = dapp
|
10
|
+
self.repository = repository
|
22
11
|
end
|
23
12
|
|
24
13
|
def image_id(tag)
|
25
|
-
|
26
|
-
response['config']['digest'] if response['schemaVersion'] == 2
|
14
|
+
ruby2go_docker_registry_command(command: :image_id, options: { reference: tag_reference(tag) })
|
27
15
|
end
|
28
16
|
|
29
17
|
def image_parent_id(tag)
|
30
|
-
|
18
|
+
ruby2go_docker_registry_command(command: :image_parent_id, options: { reference: tag_reference(tag) })
|
31
19
|
end
|
32
20
|
|
33
|
-
def
|
34
|
-
|
21
|
+
def image_config(tag)
|
22
|
+
ruby2go_docker_registry_command(command: :image_config, options: { reference: tag_reference(tag) })
|
35
23
|
end
|
36
24
|
|
37
25
|
def image_delete(tag)
|
38
|
-
|
39
|
-
|
40
|
-
expects: [202, 404],
|
41
|
-
headers: { Accept: 'application/vnd.docker.distribution.manifest.v2+json' })
|
26
|
+
digest = image_digest(tag)
|
27
|
+
ruby2go_docker_registry_command(command: :image_delete, options: { reference: digest_reference(digest) })
|
42
28
|
end
|
43
29
|
|
44
|
-
def image_history(tag)
|
45
|
-
response = manifest_v1(tag)
|
46
|
-
JSON.load(response['history'].first['v1Compatibility'])
|
47
|
-
end
|
48
|
-
|
49
|
-
protected
|
50
|
-
|
51
30
|
def image_digest(tag)
|
52
|
-
|
53
|
-
headers: { Accept: 'application/vnd.docker.distribution.manifest.v2+json' }).headers['Docker-Content-Digest']
|
31
|
+
ruby2go_docker_registry_command(command: :image_digest, options: { reference: tag_reference(tag) })
|
54
32
|
end
|
55
33
|
|
56
|
-
|
57
|
-
api_request(repo_suffix, "/manifests/#{tag}")
|
58
|
-
end
|
34
|
+
protected
|
59
35
|
|
60
|
-
def
|
61
|
-
|
62
|
-
headers: { Accept: 'application/vnd.docker.distribution.manifest.v2+json' })
|
36
|
+
def tag_reference(tag = nil)
|
37
|
+
[self.repository.chomp("/"), tag].compact.join(":")
|
63
38
|
end
|
64
39
|
|
65
|
-
def
|
66
|
-
|
40
|
+
def digest_reference(digest = nil)
|
41
|
+
[self.repository.chomp("/"), digest].compact.join("@")
|
67
42
|
end
|
68
43
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rescue Excon::Error::NotFound
|
75
|
-
raise ::Dapp::Dimg::DockerRegistry::Error::ImageNotFound.new(url, api_url)
|
76
|
-
rescue Excon::Error::Unauthorized
|
77
|
-
user_not_authorized!
|
78
|
-
rescue Excon::Error => err
|
79
|
-
if err.is_a? Excon::Error::BadRequest
|
80
|
-
response_data = (JSON.load(err.response.body) rescue nil)
|
81
|
-
if response_data
|
82
|
-
(response_data["errors"] || []).each do |err_data|
|
83
|
-
if err_data["code"] == "MANIFEST_INVALID"
|
84
|
-
raise ::Dapp::Dimg::DockerRegistry::Error::ManifestInvalid.new(url, api_url, "#{err.response.status_line.strip}: #{err.response.reason_phrase.strip}: #{err.response.body.strip}")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
44
|
+
def ruby2go_docker_registry_command(command:, **options)
|
45
|
+
(options[:options] ||= {}).merge!(host_docker_config_dir: dapp.class.host_docker_config_dir)
|
46
|
+
dapp.ruby2go_docker_registry(command: command, **options).tap do |res|
|
47
|
+
raise Error::Registry, code: :ruby2go_docker_registry_command_failed_unexpected_error, data: { command: command, message: res["error"] } unless res["error"].nil?
|
48
|
+
break res['data']
|
88
49
|
end
|
89
|
-
|
90
|
-
raise(::Dapp::Dimg::DockerRegistry::Error::Base,
|
91
|
-
code: :unknown_error,
|
92
|
-
data: { url: url,
|
93
|
-
registry: api_url,
|
94
|
-
message: "#{err.response.status_line.strip}: #{err.response.reason_phrase.strip}: #{err.response.body.strip}" }
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
def api_url(*uri)
|
99
|
-
File.join(hostname_url, API_VERSION, '/', *uri)
|
100
|
-
end
|
101
|
-
|
102
|
-
def default_api_options
|
103
|
-
{ expects: [200] }
|
104
|
-
end
|
105
|
-
|
106
|
-
def user_not_authorized!
|
107
|
-
raise ::Dapp::Dimg::DockerRegistry::Error::Base, code: :user_not_authorized, data: { registry: api_url }
|
108
50
|
end
|
109
51
|
end
|
110
52
|
end # DockerRegistry
|
@@ -3,54 +3,60 @@ module Dapp
|
|
3
3
|
module DockerRegistry
|
4
4
|
class Dimg < Base
|
5
5
|
def dimgstages_tags
|
6
|
-
|
6
|
+
tags_wrapper do
|
7
|
+
ruby2go_docker_registry_command(command: :dimgstage_tags, options: { reference: tag_reference })
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
11
|
def dimg_tags(dimg_name)
|
10
|
-
|
12
|
+
tags_wrapper do
|
13
|
+
with_dimg_repository(dimg_name.to_s) do
|
14
|
+
ruby2go_docker_registry_command(command: :dimg_tags, options: { reference: tag_reference })
|
15
|
+
end
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
def nameless_dimg_tags
|
14
|
-
|
20
|
+
tags_wrapper do
|
21
|
+
ruby2go_docker_registry_command(command: :dimg_tags, options: { reference: tag_reference })
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
|
-
def
|
18
|
-
|
19
|
-
rescue
|
20
|
-
raise unless e.net_status[:
|
25
|
+
def tags_wrapper
|
26
|
+
yield || []
|
27
|
+
rescue Error::Registry => e
|
28
|
+
raise unless e.net_status[:data][:message].include?("NAME_UNKNOWN")
|
21
29
|
[]
|
22
30
|
end
|
23
31
|
|
24
|
-
def image_id(tag,
|
25
|
-
|
32
|
+
def image_id(tag, dimg_repository = nil)
|
33
|
+
with_dimg_repository(dimg_repository.to_s) { super(tag) }
|
26
34
|
end
|
27
35
|
|
28
|
-
def image_parent_id(tag,
|
29
|
-
|
36
|
+
def image_parent_id(tag, dimg_repository = nil)
|
37
|
+
with_dimg_repository(dimg_repository.to_s) { super(tag) }
|
30
38
|
end
|
31
39
|
|
32
|
-
def
|
33
|
-
|
40
|
+
def image_config(tag, dimg_repository = nil)
|
41
|
+
with_dimg_repository(dimg_repository.to_s) { super(tag) }
|
34
42
|
end
|
35
43
|
|
36
|
-
def image_delete(tag,
|
37
|
-
|
44
|
+
def image_delete(tag, dimg_repository = nil)
|
45
|
+
with_dimg_repository(dimg_repository.to_s) { super(tag) }
|
38
46
|
end
|
39
47
|
|
40
|
-
def
|
41
|
-
|
42
|
-
(@image_history ||= {})[[repo_suffix, tag]] ||= super(tag)
|
43
|
-
end
|
48
|
+
def image_digest(tag, dimg_repository = nil)
|
49
|
+
with_dimg_repository(dimg_repository.to_s) { super(tag) }
|
44
50
|
end
|
45
51
|
|
46
52
|
protected
|
47
53
|
|
48
|
-
def
|
49
|
-
|
50
|
-
@
|
54
|
+
def with_dimg_repository(dimg_repository)
|
55
|
+
old_repository = repository
|
56
|
+
@repository = File.join(old_repository, dimg_repository)
|
51
57
|
yield
|
52
58
|
ensure
|
53
|
-
@
|
59
|
+
@repository = old_repository
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end # DockerRegistry
|
@@ -85,7 +85,7 @@ module Dapp
|
|
85
85
|
docker_image_id = TEMPLATE_EMPTY_VALUE
|
86
86
|
unless fake || without_registry
|
87
87
|
begin
|
88
|
-
dimg_labels = dapp.dimg_registry(repo).
|
88
|
+
dimg_labels = dapp.dimg_registry(repo).image_config(docker_tag, dimg.name)["config"]["Labels"]
|
89
89
|
docker_image_id = dapp.dimg_registry(repo).image_id(docker_tag, dimg.name)
|
90
90
|
rescue ::Dapp::Dimg::Error::Registry => err
|
91
91
|
unless disable_warnings
|
@@ -50,11 +50,12 @@ module Dapp
|
|
50
50
|
|
51
51
|
dapp.log_step("[#{Time.now}] Poll deployment '#{d.name}' status")
|
52
52
|
dapp.with_log_indent do
|
53
|
-
dapp.log_info("
|
54
|
-
dapp.log_info("Updated replicas: #{_field_value_for_log(d.status['updatedReplicas'])}")
|
55
|
-
dapp.log_info("Available replicas: #{_field_value_for_log(d.status['availableReplicas'])}")
|
56
|
-
dapp.log_info("Unavailable replicas: #{_field_value_for_log(d.status['unavailableReplicas'])}")
|
53
|
+
dapp.log_info("Target replicas: #{_field_value_for_log(d.replicas)}")
|
54
|
+
dapp.log_info("Updated replicas: #{_field_value_for_log(d.status['updatedReplicas'])} / #{_field_value_for_log(d.replicas)}")
|
55
|
+
dapp.log_info("Available replicas: #{_field_value_for_log(d.status['availableReplicas'])} / #{_field_value_for_log(d.replicas)}")
|
57
56
|
dapp.log_info("Ready replicas: #{_field_value_for_log(d.status['readyReplicas'])} / #{_field_value_for_log(d.replicas)}")
|
57
|
+
dapp.log_info("Old deployment.kubernetes.io/revision: #{_field_value_for_log(@revision_before_deploy)}")
|
58
|
+
dapp.log_info("Current deployment.kubernetes.io/revision: #{_field_value_for_log(d_revision)}")
|
58
59
|
end
|
59
60
|
|
60
61
|
rs = nil
|
@@ -83,16 +84,6 @@ module Dapp
|
|
83
84
|
end
|
84
85
|
|
85
86
|
if rs
|
86
|
-
dapp.with_log_indent do
|
87
|
-
dapp.log_step("Current ReplicaSet '#{rs.name}' status")
|
88
|
-
dapp.with_log_indent do
|
89
|
-
dapp.log_info("Replicas: #{_field_value_for_log(rs.status['replicas'])}")
|
90
|
-
dapp.log_info("Fully labeled replicas: #{_field_value_for_log(rs.status['fullyLabeledReplicas'])}")
|
91
|
-
dapp.log_info("Available replicas: #{_field_value_for_log(rs.status['availableReplicas'])}")
|
92
|
-
dapp.log_info("Ready replicas: #{_field_value_for_log(rs.status['readyReplicas'])} / #{_field_value_for_log(d.replicas)}")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
87
|
# Pod'ы связанные с активным ReplicaSet
|
97
88
|
rs_pods = dapp.kubernetes.pod_list['items']
|
98
89
|
.map {|spec| Kubernetes::Client::Resource::Pod.new(spec)}
|
@@ -177,14 +168,19 @@ module Dapp
|
|
177
168
|
end # with_log_indent
|
178
169
|
end
|
179
170
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
171
|
+
if d_revision && d.replicas
|
172
|
+
if d.replicas == 0
|
173
|
+
break
|
174
|
+
else
|
175
|
+
break if begin
|
176
|
+
d.status['updatedReplicas'] &&
|
177
|
+
d.status['availableReplicas'] &&
|
178
|
+
d.status['readyReplicas'] &&
|
179
|
+
(d.status['updatedReplicas'] >= d.replicas) &&
|
180
|
+
(d.status['availableReplicas'] >= d.replicas) &&
|
181
|
+
(d.status['readyReplicas'] >= d.replicas)
|
182
|
+
end
|
183
|
+
end
|
188
184
|
end
|
189
185
|
|
190
186
|
sleep 5
|
@@ -193,14 +189,6 @@ module Dapp
|
|
193
189
|
end
|
194
190
|
end
|
195
191
|
|
196
|
-
def is_deployment_ready(d)
|
197
|
-
d.status.key?("readyReplicas") && d.status["readyReplicas"] >= d.replicas
|
198
|
-
end
|
199
|
-
|
200
|
-
def is_replicaset_ready(d, rs)
|
201
|
-
rs.status.key?("readyReplicas") && rs.status["readyReplicas"] >= d.replicas
|
202
|
-
end
|
203
|
-
|
204
192
|
private
|
205
193
|
|
206
194
|
def _field_value_for_log(value)
|
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.35.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:
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -627,11 +627,7 @@ files:
|
|
627
627
|
- lib/dapp/dimg/dimg/stages.rb
|
628
628
|
- lib/dapp/dimg/docker_registry.rb
|
629
629
|
- lib/dapp/dimg/docker_registry/base.rb
|
630
|
-
- lib/dapp/dimg/docker_registry/base/authorization.rb
|
631
|
-
- lib/dapp/dimg/docker_registry/base/request.rb
|
632
|
-
- lib/dapp/dimg/docker_registry/default.rb
|
633
630
|
- lib/dapp/dimg/docker_registry/dimg.rb
|
634
|
-
- lib/dapp/dimg/docker_registry/error.rb
|
635
631
|
- lib/dapp/dimg/error/build.rb
|
636
632
|
- lib/dapp/dimg/error/chef.rb
|
637
633
|
- lib/dapp/dimg/error/default.rb
|
@@ -744,7 +740,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
744
740
|
version: 2.5.0
|
745
741
|
requirements: []
|
746
742
|
rubyforge_project:
|
747
|
-
rubygems_version: 2.7.
|
743
|
+
rubygems_version: 2.7.7
|
748
744
|
signing_key:
|
749
745
|
specification_version: 4
|
750
746
|
summary: Build docker packaged apps using chef or shell
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Dimg
|
3
|
-
module DockerRegistry
|
4
|
-
class Base
|
5
|
-
module Authorization
|
6
|
-
def authorization_options(url, method:)
|
7
|
-
(@authorization_options ||= {})[[@repo_suffix, method]] ||= begin
|
8
|
-
case authenticate_header = raw_request(url, method: method).headers['Www-Authenticate']
|
9
|
-
when /Bearer/ then { headers: { Authorization: "Bearer #{authorization_token(authenticate_header)}" } }
|
10
|
-
when /Basic/ then { headers: { Authorization: "Basic #{authorization_auth}" } }
|
11
|
-
when nil then {}
|
12
|
-
else raise ::Dapp::Dimg::DockerRegistry::Error::Base, code: :authenticate_type_not_supported, data: { registry: api_url }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def authorization_token(authenticate_header)
|
18
|
-
options = parse_authenticate_header(authenticate_header)
|
19
|
-
realm = options.delete(:realm)
|
20
|
-
begin
|
21
|
-
response = raw_request(realm, headers: { Authorization: "Basic #{authorization_auth}" }, query: options, expects: [200])
|
22
|
-
rescue ::Dapp::Dimg::DockerRegistry::Error::Base
|
23
|
-
raise unless (response = raw_request(realm, query: options)).status == 200
|
24
|
-
end
|
25
|
-
JSON.load(response.body)['token']
|
26
|
-
end
|
27
|
-
|
28
|
-
def parse_authenticate_header(header)
|
29
|
-
[:realm, :service, :scope].map do |option|
|
30
|
-
/#{option}="([[^"].]*)/ =~ header
|
31
|
-
next unless Regexp.last_match(1)
|
32
|
-
[option, Regexp.last_match(1)]
|
33
|
-
end.compact.to_h
|
34
|
-
end
|
35
|
-
|
36
|
-
def authorization_auth
|
37
|
-
@authorization_auth ||= begin
|
38
|
-
if ::Dapp::Dapp.options_with_docker_credentials?
|
39
|
-
Base64.strict_encode64(::Dapp::Dapp.docker_credentials.join(':'))
|
40
|
-
else
|
41
|
-
auths = auths_section_from_docker_config
|
42
|
-
r = repo
|
43
|
-
loop do
|
44
|
-
break unless r.include?('/') && !auths.keys.any? { |auth| auth.start_with?(r) }
|
45
|
-
r = chomp_name(r)
|
46
|
-
end
|
47
|
-
credential = (auths[r] || auths.find { |repo, _| repo == r })
|
48
|
-
user_not_authorized! if credential.nil?
|
49
|
-
credential['auth']
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def auths_section_from_docker_config
|
55
|
-
file = Pathname(File.join(::Dapp::Dapp.host_docker_config_dir, 'config.json'))
|
56
|
-
user_not_authorized! unless file.exist?
|
57
|
-
JSON.load(file.read)['auths'].tap { |auths| user_not_authorized! if auths.nil? }
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def chomp_name(r)
|
63
|
-
r.split('/')[0..-2].join('/')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end # Base
|
67
|
-
end # DockerRegistry
|
68
|
-
end # Dimg
|
69
|
-
end # Dapp
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Dimg
|
3
|
-
module DockerRegistry
|
4
|
-
class Base
|
5
|
-
module Request
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(self)
|
8
|
-
end
|
9
|
-
|
10
|
-
def request(url, **options)
|
11
|
-
raw_request(url, options.in_depth_merge(authorization_options(url, method: options[:method] || :get)))
|
12
|
-
end
|
13
|
-
|
14
|
-
def raw_request(url, **options)
|
15
|
-
Excon.new(url).request(default_request_options.in_depth_merge(options))
|
16
|
-
end
|
17
|
-
|
18
|
-
def url_available?(url)
|
19
|
-
raw_request(url, expects: [200])
|
20
|
-
true
|
21
|
-
rescue Excon::Error
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
protected
|
26
|
-
|
27
|
-
def default_request_options
|
28
|
-
{ method: :get, omit_default_port: true }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end # Base
|
32
|
-
end # DockerRegistry
|
33
|
-
end # Dimg
|
34
|
-
end # Dapp
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Dimg
|
3
|
-
module DockerRegistry
|
4
|
-
class Default < Dimg
|
5
|
-
DEFAULT_HOSTNAME_URL = 'https://registry.hub.docker.com'.freeze
|
6
|
-
|
7
|
-
def initialize(repo, repo_suffix)
|
8
|
-
super(repo, DEFAULT_HOSTNAME_URL, repo_suffix)
|
9
|
-
end
|
10
|
-
|
11
|
-
def repo_suffix=(val)
|
12
|
-
val = "library/#{val}" if val.split('/').one?
|
13
|
-
super(val)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end # Dimg
|
18
|
-
end # Dapp
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Dapp
|
2
|
-
module Dimg
|
3
|
-
module DockerRegistry
|
4
|
-
module Error
|
5
|
-
class Base < ::Dapp::Dimg::Error::Registry
|
6
|
-
def initialize(**net_status)
|
7
|
-
super(**net_status, context: :registry)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ManifestInvalid < Base
|
12
|
-
def initialize(url, registry, response_body)
|
13
|
-
super(code: :manifest_invalid, data: {url: url, registry: registry, response_body: response_body})
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class ImageNotFound < Base
|
18
|
-
def initialize(url, registry)
|
19
|
-
super(code: :page_not_found, data: { url: url, registry: registry })
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end # Error
|
23
|
-
end # DockerRegistry
|
24
|
-
end # Dimg
|
25
|
-
end # Dapp
|