Class: Retag::Image
Instance Attribute Summary collapse
-
#full ⇒ Object
readonly
Returns the value of attribute full.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
-
#initialize(image, tag, suffix: nil) ⇒ Image
constructor
A new instance of Image.
- #retag!(newtag = tag) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(image, tag, suffix: nil) ⇒ Image
Returns a new instance of Image.
10 11 12 13 14 15 |
# File 'lib/retag/image.rb', line 10 def initialize(image, tag, suffix: nil) @image = image @tag = tag @tag = "#{@tag}-#{suffix}" if suffix.present? @full = "#{@image}:#{@tag}" end |
Instance Attribute Details
#full ⇒ Object (readonly)
Returns the value of attribute full.
8 9 10 |
# File 'lib/retag/image.rb', line 8 def full @full end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
8 9 10 |
# File 'lib/retag/image.rb', line 8 def image @image end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
8 9 10 |
# File 'lib/retag/image.rb', line 8 def tag @tag end |
Instance Method Details
#retag!(newtag = tag) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/retag/image.rb', line 17 def retag!(newtag = tag) uri = ::URI.parse("https://#{image}") repo = uri.path repo[0..0] = '' uri.path = '' content_type = 'application/vnd.docker.distribution.manifest.v2+json' Tempfile.create('manifest') do |file| manifest = JSON.parse(cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Accept: #{content_type}' '#{uri}/v2/#{repo}/manifests/#{tag}' -o -", capture: true).strip) raise manifest.inspect unless manifest.dig('layers') || manifest.dig('config') file.write(manifest.to_json) file.flush 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 raise result unless result.empty? end Image.new(image, newtag) end |