retag 0.2.3.292162 → 0.2.5.292559

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ddd54552ea5d4a5246b1b93d35455d13b5134625d589049a0b33a141d1b284
4
- data.tar.gz: 7833bafabc8df095f7e2c2ab82cc4507142887430873d925aa155b43a5a3e29f
3
+ metadata.gz: 90d9bfab918098f2487693ffde7bbde4840ececd02b8a3805ae62545ca848c26
4
+ data.tar.gz: a71c3e364ca9eb549462e46abada8ccf5cb691e5e23f044bec05a24fef818141
5
5
  SHA512:
6
- metadata.gz: 065bb196dced3c82fe22fdae678e27dd426eddf8c209300dbd9636b49daf039f74a610582f1390795d82b6f65b78c124189b9d8fe2bd536c31de235b1b192319
7
- data.tar.gz: 1dd9cc1e109b517620f58b55449381966ca20c64b78e38efb220b9fbc9656a45b1c263f3c0b8f1cd931312308c98ee136f0810192c7e6c72750d5aa67e5c60e7
6
+ metadata.gz: 3ed632175b194d63a8f7e937fd60005f5edd5f30ffc318d8db91b898710ee055d52e4f2bfdb9d9bc8373d595345f0476566be095b01bd275434fe954440378b1
7
+ data.tar.gz: 59d3aebec259f3eaad3f460ac4123d935631f51504184eb0bf804e6c936247b253030ed92c387c40627e02c90f3313d0ed5d8f72e41415804a6dd62b8e880174
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retag (0.2.3)
4
+ retag (0.2.5)
5
5
  activesupport (~> 6.0)
6
6
  colorize (~> 0.8.1)
7
7
  gitlab (< 5.0)
data/lib/retag/image.rb CHANGED
@@ -5,7 +5,7 @@ module Retag
5
5
  class Image
6
6
 
7
7
  include Utils
8
- attr_reader :full, :image, :tag, :api
8
+ attr_reader :full, :image, :tag, :api, :repo, :uri
9
9
 
10
10
  def initialize(image, tag, suffix: nil, api: nil)
11
11
  @image = image
@@ -13,48 +13,60 @@ module Retag
13
13
  @tag = "#{@tag}-#{suffix}" if suffix.present?
14
14
  @full = "#{@image}:#{@tag}"
15
15
  @api = api
16
+
17
+ @uri = ::URI.parse("https://#{@image}").normalize
18
+ @repo = @uri.path
19
+ @repo[0..0] = ''
20
+ @uri.path = ''
16
21
  end
17
22
 
18
- def retag!(newtag = tag, newproject: nil)
19
- uri = ::URI.parse("https://#{image}")
20
- repo = uri.path
21
- repo[0..0] = ''
23
+ MANIFEST_CONTENT_TYPE = 'application/vnd.docker.distribution.manifest.v2+json'
22
24
 
23
- project, *_ = repo.split('/')
24
- registry = repo.split('/').join('-')
25
- uri.path = ''
25
+ def retag!(newtag = tag, newproject: nil)
26
+ project, *_rest = repo.split('/')
27
+ registry = repo
26
28
  newrepo = "#{newproject}/#{registry}"
27
29
 
28
- content_type = 'application/vnd.docker.distribution.manifest.v2+json'
29
-
30
30
  Tempfile.create('manifest') do |file|
31
- manifest = JSON.parse(cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Accept: #{content_type}' '#{uri}/v2/#{repo}/manifests/#{tag}' -o -", capture: true).strip)
32
- raise manifest.inspect unless manifest.dig('layers') || manifest.dig('config') || manifest.dig('manifests')
33
-
31
+ manifest = get_manifest
34
32
  file.write(manifest.to_json)
35
33
  file.flush
36
34
 
37
35
  if newtag.to_s.strip != tag.to_s.strip
38
- 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
36
+ result = cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Content-Type: #{MANIFEST_CONTENT_TYPE}' -H 'Accept: #{MANIFEST_CONTENT_TYPE}' -X PUT --data-binary @#{file.path} '#{uri}/v2/#{repo}/manifests/#{newtag}' -o -", capture: true).strip
39
37
  raise result unless result.empty?
40
38
  end
41
39
 
42
- if project != newproject
43
- if api == 'harbor'
44
- 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
45
- else
40
+ if newproject && project != newproject
41
+ unless api == 'harbor'
46
42
  raise "Unable to promote image #{repo} -> #{newrepo} with #{api.inspect} api: Unimplemented"
47
43
  end
44
+
45
+ newregistry = registry.split('/').join('-')
46
+ newrepo = "#{newproject}/#{newregistry}"
47
+
48
+ result = cmd!(
49
+ "curl -s -u '#{dockerauth(uri.host)}' -X POST '#{uri}/api/v2.0/projects/#{newproject}/repositories/#{newregistry}/artifacts?from=#{repo}:#{newtag}' -o -", capture: true
50
+ ).strip
48
51
  end
49
52
 
50
53
  raise result unless result.empty?
51
54
  end
52
55
 
53
56
  newuri = uri.dup
54
- newuri.path = "/#{newrepo}"
57
+ newuri.path = "/#{newrepo}".gsub('//', '/')
55
58
  Image.new(newuri.hostname + newuri.path, newtag)
56
59
  end
57
60
 
61
+ def get_manifest
62
+ manifest = JSON.parse(cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Accept: #{MANIFEST_CONTENT_TYPE}' '#{uri}/v2/#{repo}/manifests/#{tag}' -o -", capture: true).strip)
63
+ unless manifest.dig('layers') || manifest.dig('config') || manifest.dig('manifests')
64
+ raise manifest.inspect
65
+ end
66
+
67
+ manifest
68
+ end
69
+
58
70
  end
59
71
  end
60
72
 
data/lib/retag/utils.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'base64'
2
2
  require 'open3'
3
+ require 'colorize'
3
4
 
4
5
  module Retag
5
6
  module Utils
@@ -12,6 +13,8 @@ module Retag
12
13
 
13
14
  logger.tagged("CMD#{tag}".colorize(:light_black)) { logger.debug cmd.colorize(:light_black) }
14
15
 
16
+ return output if $dryrun
17
+
15
18
  code = Open3.popen3(cmd) do |stdin, stdout, stderr, thr|
16
19
  stdin.close_write
17
20
  files = [stdout, stderr]
data/lib/retag/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Retag
4
4
 
5
- VERSION = '0.2.3'
5
+ VERSION = '0.2.5'
6
6
 
7
7
  end
8
8
 
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.2.3.292162
4
+ version: 0.2.5.292559
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-02-28 00:00:00.000000000 Z
11
+ date: 2025-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler