class Hippo::Image
Attributes
name[R]
Public Class Methods
new(name, options)
click to toggle source
# File lib/hippo/image.rb, line 9 def initialize(name, options) @name = name @options = options end
Public Instance Methods
can_check_for_existence?()
click to toggle source
# File lib/hippo/image.rb, line 53 def can_check_for_existence? @options['existenceCheck'].nil? || @options['existenceCheck'] == true end
exists?()
click to toggle source
# File lib/hippo/image.rb, line 58 def exists? return true unless tag.is_a?(RepositoryTag) return true if host.nil? return true unless can_check_for_existence? credentials = Hippo.config.dig('docker', 'credentials', host) http = Net::HTTP.new(host, 443) http.use_ssl = true request = Net::HTTP::Head.new("/v2/#{image_name}/manifests/#{tag}") if credentials request.basic_auth(credentials['username'], credentials['password']) end response = http.request(request) case response when Net::HTTPOK true when Net::HTTPUnauthorized raise Error, "Could not authenticate to #{host} to verify image existence" when Net::HTTPNotFound false else raise Error, "Got #{response.code} status when verifying imag existence with #{host}" end end
host()
click to toggle source
# File lib/hippo/image.rb, line 16 def host @options['host'] end
image_name()
click to toggle source
# File lib/hippo/image.rb, line 20 def image_name @options['name'] end
image_url()
click to toggle source
# File lib/hippo/image.rb, line 36 def image_url if host "#{host}/#{image_name}:#{tag}" else "#{image_name}:#{tag}" end end
tag()
click to toggle source
# File lib/hippo/image.rb, line 24 def tag @tag ||= begin if @options['tag'].is_a?(Hash) && repo = @options['tag']['fromRepository'] RepositoryTag.new(repo) elsif @options['tag'].nil? 'latest' else @options['tag'].to_s end end end
template_vars()
click to toggle source
# File lib/hippo/image.rb, line 44 def template_vars @template_vars ||= { 'host' => host, 'name' => image_name, 'tag' => tag.to_s, 'url' => image_url } end