retag 0.2.3.292145 → 0.2.4.292196

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: dfd82cee3c87de048b6214ef7a0173613f95b37dfd8b319f8390db1435f9991d
4
- data.tar.gz: ea57ecd03f22ca187b4451e2fe74afb600c4406f6138cd830b9c9ab3cdb4b5d9
3
+ metadata.gz: 320ce12c46e6e61bc78b7007c8baf2c8d66b20490e22a0117dc6593eba9d9f45
4
+ data.tar.gz: d4251f9933060d9a0edd218927229bc24f9195a347624f8b3f5b5cca6ad8c11e
5
5
  SHA512:
6
- metadata.gz: 477a6516d475c3d67374c2d12b95add4d058ef735e70f3b5bca06d0771f19f61aa55f6fa676567a13b40d57b2533e7de47db547af1e515380d8457011d0e4fdf
7
- data.tar.gz: 97b96d075dd8bc143e207d5f3ae070997893de10ce88254f26e2b6e1d77e5740569d139472e200f336692135eef01526cc05d2110f7640c38cbbf953c38653ad
6
+ metadata.gz: d7e8bd5d28d6fbc783eb4cd4a279ebddd9153427e54507546284bcb1701827286229899260f0bdbad3d315cb04fc87268a91c725ecd9001488d742e8508610ff
7
+ data.tar.gz: 888f0abf99b2581010b619bf373219c61a6a2a14050f0f1e612f2b66af9f95f7d97619bf1de260de03752ff0efb8a0bcc7840bdbd518b6bd107d404c449d324b
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.4)
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,58 @@ 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 newrepo != repo
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
+ newrepo = "#{newproject}/#{registry.split('/').join('-')}"
46
+ result = cmd!(
47
+ "curl -s -u '#{dockerauth(uri.host)}' -X POST '#{uri}/api/v2.0/projects/#{newproject}/repositories/#{registry}/artifacts?from=#{repo}:#{newtag}' -o -", capture: true
48
+ ).strip
48
49
  end
49
50
 
50
51
  raise result unless result.empty?
51
52
  end
52
53
 
53
54
  newuri = uri.dup
54
- newuri.path = "/#{newrepo}"
55
+ newuri.path = "/#{newrepo}".gsub('//', '/')
55
56
  Image.new(newuri.hostname + newuri.path, newtag)
56
57
  end
57
58
 
59
+ def get_manifest
60
+ manifest = JSON.parse(cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Accept: #{MANIFEST_CONTENT_TYPE}' '#{uri}/v2/#{repo}/manifests/#{tag}' -o -", capture: true).strip)
61
+ unless manifest.dig('layers') || manifest.dig('config') || manifest.dig('manifests')
62
+ raise manifest.inspect
63
+ end
64
+
65
+ manifest
66
+ end
67
+
58
68
  end
59
69
  end
60
70
 
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.4'
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.292145
4
+ version: 0.2.4.292196
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-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler