Class: Lemans::Config::ImageSpec
- Inherits:
-
Object
- Object
- Lemans::Config::ImageSpec
- Defined in:
- lib/lemans/config/image_spec.rb
Overview
An image, either already published or built from a task's Dockerfile. Built images are named by content digest, so reuse is only ever of the identical thing.
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#dockerfile_path ⇒ Object
readonly
Returns the value of attribute dockerfile_path.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Class Method Summary collapse
Instance Method Summary collapse
- #built? ⇒ Boolean
- #context_dir ⇒ Object
-
#initialize(reference: nil, dockerfile_path: nil, slug: nil) ⇒ ImageSpec
constructor
A new instance of ImageSpec.
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(reference: nil, dockerfile_path: nil, slug: nil) ⇒ ImageSpec
Returns a new instance of ImageSpec.
22 23 24 25 26 27 28 29 |
# File 'lib/lemans/config/image_spec.rb', line 22 def initialize(reference: nil, dockerfile_path: nil, slug: nil) @reference = reference @dockerfile_path = dockerfile_path @slug = slug # Hashing the reference gives backends one answer to "is this the same image" either way. @digest = built? ? TreeDigest.call(context_dir) : Digest::SHA256.hexdigest(reference.to_s) end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
11 12 13 |
# File 'lib/lemans/config/image_spec.rb', line 11 def digest @digest end |
#dockerfile_path ⇒ Object (readonly)
Returns the value of attribute dockerfile_path.
11 12 13 |
# File 'lib/lemans/config/image_spec.rb', line 11 def dockerfile_path @dockerfile_path end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
11 12 13 |
# File 'lib/lemans/config/image_spec.rb', line 11 def reference @reference end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
11 12 13 |
# File 'lib/lemans/config/image_spec.rb', line 11 def slug @slug end |
Class Method Details
.dockerfile(path, slug:) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/lemans/config/image_spec.rb', line 15 def self.dockerfile(path, slug:) path = Pathname(path) raise ConfigError, "no Dockerfile at #{path}" unless path.file? new(dockerfile_path: path, slug:) end |
.registry(reference) ⇒ Object
13 |
# File 'lib/lemans/config/image_spec.rb', line 13 def self.registry(reference) = new(reference:) |
Instance Method Details
#built? ⇒ Boolean
31 |
# File 'lib/lemans/config/image_spec.rb', line 31 def built? = !dockerfile_path.nil? |
#context_dir ⇒ Object
33 |
# File 'lib/lemans/config/image_spec.rb', line 33 def context_dir = dockerfile_path&.dirname |
#name ⇒ Object
35 36 37 |
# File 'lib/lemans/config/image_spec.rb', line 35 def name built? ? "lemans-#{digest[0, 32]}" : reference end |
#to_s ⇒ Object
39 |
# File 'lib/lemans/config/image_spec.rb', line 39 def to_s = name |