retag 0.1.11.286383 → 0.2.2.290087
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bin/retag +20 -4
- data/lib/retag/image.rb +24 -5
- 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: d08628d204433079ea7b5345a7ee74e0fcc9e2b9b06110383fc9002a238c392a
|
4
|
+
data.tar.gz: 1a7e52183548f21bbb8019c07e5e0f13c98c56305d9ebe26a06218122a292566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437fa7228f9cbeb0c1bb301471b81093fb90394874b4ac11849c4d5bf36e02c5866064cc5be10e9ea246171e74ca7e7ae24ace3f6f0ecd6a7b0ba0be7ce40764
|
7
|
+
data.tar.gz: 7105927440b35adfe9014b4517fcce922f895df5e98aa8453fc83f83daac5e417d811a81514e645375a785d8c05d32879ea458bf9a68cae900490e1a48468a1c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retag (0.
|
4
|
+
retag (0.2.2)
|
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, *center, 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,26 @@ module Retag
|
|
28
32
|
|
29
33
|
file.write(manifest.to_json)
|
30
34
|
file.flush
|
31
|
-
|
35
|
+
|
36
|
+
if newtag.to_s.strip != tag.to_s.strip
|
37
|
+
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
|
38
|
+
raise result unless result.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
if newrepo != repo
|
42
|
+
if api == 'harbor'
|
43
|
+
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
|
44
|
+
else
|
45
|
+
raise "Unable to promote image #{repo} -> #{newrepo} with #{api.inspect} api: Unimplemented"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
32
49
|
raise result unless result.empty?
|
33
50
|
end
|
34
51
|
|
35
|
-
|
52
|
+
newuri = uri.dup
|
53
|
+
newuri.path = "/#{newrepo}"
|
54
|
+
Image.new(newuri.hostname + newuri.path, newtag)
|
36
55
|
end
|
37
56
|
|
38
57
|
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.
|
4
|
+
version: 0.2.2.290087
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|