Class: Hippo::Image
- Inherits:
-
Object
- Object
- Hippo::Image
- Defined in:
- lib/hippo/image.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #can_check_for_existence? ⇒ Boolean
- #exists? ⇒ Boolean
- #host ⇒ Object
- #image_name ⇒ Object
- #image_url ⇒ Object
-
#initialize(name, options) ⇒ Image
constructor
A new instance of Image.
- #tag ⇒ Object
- #template_vars ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Image
Returns a new instance of Image.
9 10 11 12 |
# File 'lib/hippo/image.rb', line 9 def initialize(name, ) @name = name @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/hippo/image.rb', line 14 def name @name end |
Instance Method Details
#can_check_for_existence? ⇒ Boolean
53 54 55 56 |
# File 'lib/hippo/image.rb', line 53 def can_check_for_existence? @options['existenceCheck'].nil? || @options['existenceCheck'] == true end |
#exists? ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/hippo/image.rb', line 16 def host @options['host'] end |
#image_name ⇒ Object
20 21 22 |
# File 'lib/hippo/image.rb', line 20 def image_name @options['name'] end |
#image_url ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/hippo/image.rb', line 36 def image_url if host "#{host}/#{image_name}:#{tag}" else "#{image_name}:#{tag}" end end |
#tag ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
44 45 46 47 48 49 50 51 |
# 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 |