Class: Lemans::Config::ImageSpec

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

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.



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

#digestObject (readonly)

Returns the value of attribute digest.



11
12
13
# File 'lib/lemans/config/image_spec.rb', line 11

def digest
  @digest
end

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

#referenceObject (readonly)

Returns the value of attribute reference.



11
12
13
# File 'lib/lemans/config/image_spec.rb', line 11

def reference
  @reference
end

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

Raises:



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

Returns:

  • (Boolean)


31
# File 'lib/lemans/config/image_spec.rb', line 31

def built? = !dockerfile_path.nil?

#context_dirObject



33
# File 'lib/lemans/config/image_spec.rb', line 33

def context_dir = dockerfile_path&.dirname

#nameObject



35
36
37
# File 'lib/lemans/config/image_spec.rb', line 35

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

#to_sObject



39
# File 'lib/lemans/config/image_spec.rb', line 39

def to_s = name