Class: Dash::Dockerfile::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/dockerfile/stage.rb

Overview

One build stage: everything from a FROM up to the next one.

shipped? is the distinction that matters for advice. A stage only reachable through COPY --from= contributes files, not layers, so apt hygiene and a missing USER in it say nothing about the image that ends up on the server. The last stage is shipped, and so is anything it (transitively) builds FROM.

Constant Summary collapse

IMAGE_REF =

A registry may carry a port (localhost:5000/app), so the tag is only what follows a colon in the last path segment.

%r{\A(?<image>(?:[^/@\s]+/)*[^:/@\s]+)(?::(?<tag>[^@\s]+))?(?:@(?<digest>\S+))?\z}
INTERPOLATION =
/\$\{?\w+\}?/
SCRATCH =

Docker's reserved empty base: nothing to pin, nothing to resolve.

"scratch".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, index:, base:, from:, named: true) ⇒ Stage

Returns a new instance of Stage.



18
19
20
21
22
23
24
25
26
# File 'lib/dash/dockerfile/stage.rb', line 18

def initialize(name:, index:, base:, from:, named: true)
  @name = name
  @named = named
  @index = index
  @base = base
  @from = from
  @instructions = [ from ]
  @shipped = false
end

Instance Attribute Details

#base ⇒ Object (readonly)

Returns the value of attribute base.



15
16
17
# File 'lib/dash/dockerfile/stage.rb', line 15

def base
  @base
end

#index ⇒ Object (readonly)

Returns the value of attribute index.



15
16
17
# File 'lib/dash/dockerfile/stage.rb', line 15

def index
  @index
end

#instructions ⇒ Object (readonly)

Returns the value of attribute instructions.



15
16
17
# File 'lib/dash/dockerfile/stage.rb', line 15

def instructions
  @instructions
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/dash/dockerfile/stage.rb', line 15

def name
  @name
end

#shipped=(value) ⇒ Object (writeonly)

Sets the attribute shipped

Parameters:

  • value —

    the value to set the attribute shipped to.



16
17
18
# File 'lib/dash/dockerfile/stage.rb', line 16

def shipped=(value)
  @shipped = value
end

Instance Method Details

#digest ⇒ Object



49
50
51
# File 'lib/dash/dockerfile/stage.rb', line 49

def digest
  ref[:digest]
end

#image ⇒ Object



41
42
43
# File 'lib/dash/dockerfile/stage.rb', line 41

def image
  ref[:image]
end

#interpolated_tag? ⇒ Boolean

FROM ruby:$RUBY_VERSION pins a version through an ARG, so it is not the unpinned base the latest-base rule is looking for. With no tag at all, FROM $IMAGE might be carrying one inside the variable — unknowable, so it passes too. An explicit :latest is explicit whatever the registry in front of it was.

Returns:

  • (Boolean)


57
58
59
# File 'lib/dash/dockerfile/stage.rb', line 57

def interpolated_tag?
  (tag || image).to_s.match?(INTERPOLATION)
end

#named? ⇒ Boolean

An explicit AS name, as opposed to the stage-N label dash generates.

Returns:

  • (Boolean)


33
34
35
# File 'lib/dash/dockerfile/stage.rb', line 33

def named?
  @named
end

#scratch? ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/dash/dockerfile/stage.rb', line 37

def scratch?
  base == SCRATCH
end

#shipped? ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dash/dockerfile/stage.rb', line 28

def shipped?
  @shipped
end

#tag ⇒ Object



45
46
47
# File 'lib/dash/dockerfile/stage.rb', line 45

def tag
  ref[:tag]
end