Class: Lemans::Task::ImageSpec

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#digestObject (readonly)

Returns the value of attribute digest.



25
26
27
# File 'lib/lemans/task.rb', line 25

def digest
  @digest
end

#dockerfile_pathObject (readonly)

Returns the value of attribute dockerfile_path.



25
26
27
# File 'lib/lemans/task.rb', line 25

def dockerfile_path
  @dockerfile_path
end

#referenceObject (readonly)

Returns the value of attribute reference.



25
26
27
# File 'lib/lemans/task.rb', line 25

def reference
  @reference
end

#slugObject (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

Raises:



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

Returns:

  • (Boolean)


45
# File 'lib/lemans/task.rb', line 45

def built? = !dockerfile_path.nil?

#context_dirObject



47
# File 'lib/lemans/task.rb', line 47

def context_dir = dockerfile_path&.dirname

#nameObject



49
50
51
# File 'lib/lemans/task.rb', line 49

def name
  built? ? "lemans-#{digest[0, 32]}" : reference
end

#to_sObject



53
# File 'lib/lemans/task.rb', line 53

def to_s = name