Class: Lemans::Task::ImageSpec
- Inherits:
-
Object
- Object
- Lemans::Task::ImageSpec
- Defined in:
- lib/lemans/task.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.
36 37 38 39 40 41 42 43 |
# File 'lib/lemans/task.rb', line 36 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) freeze end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
25 26 27 |
# File 'lib/lemans/task.rb', line 25 def digest @digest end |
#dockerfile_path ⇒ Object (readonly)
Returns the value of attribute dockerfile_path.
25 26 27 |
# File 'lib/lemans/task.rb', line 25 def dockerfile_path @dockerfile_path end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
25 26 27 |
# File 'lib/lemans/task.rb', line 25 def reference @reference end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
25 26 27 |
# File 'lib/lemans/task.rb', line 25 def slug @slug end |
Class Method Details
.dockerfile(path, slug:) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/lemans/task.rb', line 29 def self.dockerfile(path, slug:) path = Pathname(path) raise ConfigError, "no Dockerfile at #{path}" unless path.file? new(dockerfile_path: path, slug: slug) end |
.registry(reference) ⇒ Object
27 |
# File 'lib/lemans/task.rb', line 27 def self.registry(reference) = new(reference: reference) |
Instance Method Details
#built? ⇒ Boolean
45 |
# File 'lib/lemans/task.rb', line 45 def built? = !dockerfile_path.nil? |
#context_dir ⇒ Object
47 |
# File 'lib/lemans/task.rb', line 47 def context_dir = dockerfile_path&.dirname |
#name ⇒ Object
49 50 51 |
# File 'lib/lemans/task.rb', line 49 def name built? ? "lemans-#{digest[0, 32]}" : reference end |
#to_s ⇒ Object
53 |
# File 'lib/lemans/task.rb', line 53 def to_s = name |