retag 0.1.11.286383 → 0.2.1.289789
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bin/retag +20 -4
- data/lib/retag/image.rb +20 -4
- data/lib/retag/service.rb +4 -3
- data/lib/retag/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b02aec116b0797e9023ac8503214e93f4ebd9036b507223133445336d824935f
|
4
|
+
data.tar.gz: 8c432f0c18632a19c671c764149c0a80d4be7a406fb0f165fdf1cf59b812eb46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb8d95b95b55b01f2aa4dbd2a4fa819a7390135488b560f6ef091eab245dbc07e99eb5f64ef69caf8f3c83fddd70c53b4555d7633b4d8a51294b2ca85571418d
|
7
|
+
data.tar.gz: 93ae41bea06c2bdf9958b7bcfa6900fc92a38b882ecab7e19d6bc837bff1f744fa1b1fd90bc1c3ab0bb0cef202d13e668ebf72784fec2a3a0c039643d6ac67fc
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retag (0.1
|
4
|
+
retag (0.2.1)
|
5
5
|
activesupport (~> 6.0)
|
6
6
|
colorize (~> 0.8.1)
|
7
7
|
gitlab (< 5.0)
|
@@ -47,7 +47,7 @@ GEM
|
|
47
47
|
concurrent-ruby (~> 1.0)
|
48
48
|
json (2.9.1)
|
49
49
|
language_server-protocol (3.17.0.4)
|
50
|
-
logger (1.6.
|
50
|
+
logger (1.6.6)
|
51
51
|
mini_mime (1.1.5)
|
52
52
|
minitest (5.25.4)
|
53
53
|
multi_xml (0.6.0)
|
data/bin/retag
CHANGED
@@ -80,6 +80,14 @@ class DockerCommand < Thor
|
|
80
80
|
required: true,
|
81
81
|
desc: "Env: #{ENV_PREFIX}_TAG_TAG. New tag"
|
82
82
|
|
83
|
+
option :project, default: ENV.fetch("#{ENV_PREFIX}_TAG_PROJECT", nil),
|
84
|
+
required: false,
|
85
|
+
desc: "Env: #{ENV_PREFIX}_TAG_PROJECT. Change repository project"
|
86
|
+
|
87
|
+
option :api, default: ENV.fetch("#{ENV_PREFIX}_TAG_API", 'harbor'),
|
88
|
+
required: false,
|
89
|
+
desc: "Env: #{ENV_PREFIX}_TAG_API. Which API user for: [harbor]"
|
90
|
+
|
83
91
|
option :suffix, default: ENV.fetch("#{ENV_PREFIX}_TAG_SUFFIX", nil),
|
84
92
|
required: false,
|
85
93
|
desc: "Env: #{ENV_PREFIX}_TAG_SUFFIX. Optional suffix added to image tag: <image>:<tag>[-<suffix>].
|
@@ -96,11 +104,11 @@ class DockerCommand < Thor
|
|
96
104
|
tag ||= 'latest'
|
97
105
|
tag = opts['suffix'].present? ? "#{tag}-#{opts['suffix']}" : tag
|
98
106
|
|
99
|
-
image = ::Retag::Image.new(img, tag)
|
107
|
+
image = ::Retag::Image.new(img, tag, api: opts['api'])
|
100
108
|
|
101
109
|
$logger.info ">>> Image #{image.image}"
|
102
110
|
$logger.info " From ".ljust(5) + "[#{image.tag.colorize(:yellow)}]: ".ljust(35) + image.full
|
103
|
-
newimg = image.retag!(opts['tag'])
|
111
|
+
newimg = image.retag!(opts['tag'], newproject: opts['project'])
|
104
112
|
$logger.info " To ".ljust(5) + "[#{newimg.tag.colorize(:yellow)}]: ".ljust(35) + newimg.full
|
105
113
|
end
|
106
114
|
|
@@ -116,6 +124,14 @@ class ReleaseCommand < Thor
|
|
116
124
|
required: true,
|
117
125
|
desc: "Env: #{ENV_PREFIX}_RELEASE_CONFIG. Path to release manifest"
|
118
126
|
|
127
|
+
option :project, default: ENV.fetch("#{ENV_PREFIX}_RELEASE_PROJECT", nil),
|
128
|
+
required: false,
|
129
|
+
desc: "Env: #{ENV_PREFIX}_TAG_PROJECT. Change Docker repository project"
|
130
|
+
|
131
|
+
option :api, default: ENV.fetch("#{ENV_PREFIX}_RELEASE_API", 'harbor'),
|
132
|
+
required: false,
|
133
|
+
desc: "Env: #{ENV_PREFIX}_TAG_API. Which API user for: [harbor]"
|
134
|
+
|
119
135
|
option :name, default: ENV.fetch("#{ENV_PREFIX}_RELEASE_NAME", nil),
|
120
136
|
required: false,
|
121
137
|
desc: "Env: #{ENV_PREFIX}_RELEASE_NAME. Name of the current release"
|
@@ -137,7 +153,7 @@ class ReleaseCommand < Thor
|
|
137
153
|
branch = config['default-branch']
|
138
154
|
|
139
155
|
services = config['services'].map do|(name, cfg)|
|
140
|
-
Retag::Service.new(name, cfg, release, suffix: cfg.fetch('suffix', suffix), branch: cfg.fetch('branch', branch)) unless name.start_with?('.')
|
156
|
+
Retag::Service.new(name, cfg, release, suffix: cfg.fetch('suffix', suffix), branch: cfg.fetch('branch', branch), api: opts['api']) unless name.start_with?('.')
|
141
157
|
end.compact
|
142
158
|
|
143
159
|
tag_message = "Release #{release} at #{DateTime.now.iso8601}"
|
@@ -155,7 +171,7 @@ class ReleaseCommand < Thor
|
|
155
171
|
|
156
172
|
$logger.shift do
|
157
173
|
$logger.info "From ".ljust(5) + "[#{img.tag.colorize(:yellow)}]: ".ljust(35) + img.full
|
158
|
-
newimg = img.retag!(release)
|
174
|
+
newimg = img.retag!(release, newproject: opts['project'])
|
159
175
|
$logger.info "To ".ljust(5) + "[#{newimg.tag.colorize(:yellow)}]: ".ljust(35) + newimg.full
|
160
176
|
|
161
177
|
markdown += "* **Name**: `#{srv.name}`<br>**Version**: #{img.tag}<br>**Image**: #{newimg.full}\n"
|
data/lib/retag/image.rb
CHANGED
@@ -5,20 +5,24 @@ module Retag
|
|
5
5
|
class Image
|
6
6
|
|
7
7
|
include Utils
|
8
|
-
attr_reader :full, :image, :tag
|
8
|
+
attr_reader :full, :image, :tag, :api
|
9
9
|
|
10
|
-
def initialize(image, tag, suffix: nil)
|
10
|
+
def initialize(image, tag, suffix: nil, api: nil)
|
11
11
|
@image = image
|
12
12
|
@tag = tag
|
13
13
|
@tag = "#{@tag}-#{suffix}" if suffix.present?
|
14
14
|
@full = "#{@image}:#{@tag}"
|
15
|
+
@api = api
|
15
16
|
end
|
16
17
|
|
17
|
-
def retag!(newtag = tag)
|
18
|
+
def retag!(newtag = tag, newproject: nil)
|
18
19
|
uri = ::URI.parse("https://#{image}")
|
19
20
|
repo = uri.path
|
20
21
|
repo[0..0] = ''
|
22
|
+
project, registry = repo.split('/')
|
21
23
|
uri.path = ''
|
24
|
+
newrepo = repo
|
25
|
+
newrepo = repo.sub("#{project}/", "#{newproject}/") if newproject
|
22
26
|
|
23
27
|
content_type = 'application/vnd.docker.distribution.manifest.v2+json'
|
24
28
|
|
@@ -28,11 +32,23 @@ module Retag
|
|
28
32
|
|
29
33
|
file.write(manifest.to_json)
|
30
34
|
file.flush
|
35
|
+
|
31
36
|
result = cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Content-Type: #{content_type}' -H 'Accept: #{content_type}' -X PUT --data-binary @#{file.path} '#{uri}/v2/#{repo}/manifests/#{newtag}' -o -", capture: true).strip
|
37
|
+
|
38
|
+
if newrepo != repo
|
39
|
+
if api == 'harbor'
|
40
|
+
result = cmd!("curl -s -u '#{dockerauth(uri.host)}' -X POST '#{uri}/api/v2.0/projects/#{newproject}/repositories/#{registry}/artifacts?from=#{repo}:#{newtag}' -o -", capture: true).strip
|
41
|
+
else
|
42
|
+
raise "Unable to promote image #{repo} -> #{newrepo} with #{api.inspect} api: Unimplemented"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
32
46
|
raise result unless result.empty?
|
33
47
|
end
|
34
48
|
|
35
|
-
|
49
|
+
newuri = uri.dup
|
50
|
+
newuri.path = "/#{newrepo}"
|
51
|
+
Image.new(newuri.hostname + newuri.path, newtag)
|
36
52
|
end
|
37
53
|
|
38
54
|
end
|
data/lib/retag/service.rb
CHANGED
@@ -5,20 +5,21 @@ module Retag
|
|
5
5
|
|
6
6
|
include Retag::Utils
|
7
7
|
|
8
|
-
attr_reader :name, :config, :repo, :release, :suffix
|
8
|
+
attr_reader :name, :config, :repo, :release, :suffix, :api
|
9
9
|
|
10
10
|
delegate :revision, :branch, to: :repo
|
11
11
|
|
12
|
-
def initialize(name, config, release, branch:, suffix:)
|
12
|
+
def initialize(name, config, release, branch:, suffix:, api:)
|
13
13
|
@name = name
|
14
14
|
@config = config
|
15
15
|
@repo = Retag::Repo.new(config['repo'], branch)
|
16
16
|
@release = release
|
17
17
|
@suffix = suffix
|
18
|
+
@api = api
|
18
19
|
end
|
19
20
|
|
20
21
|
def images
|
21
|
-
@images ||= config['images'].map{|img| Retag::Image.new(img, revision, suffix: @suffix) }
|
22
|
+
@images ||= config['images'].map{|img| Retag::Image.new(img, revision, suffix: @suffix, api: api) }
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
data/lib/retag/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.2.1.289789
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|