class Retag::Image
Attributes
full[R]
image[R]
tag[R]
Public Class Methods
new(image, tag, suffix: nil)
click to toggle source
# 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
Public Instance Methods
retag!(newtag = tag)
click to toggle source
# 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