Class: Dash::Build::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/build/step.rb

Overview

One buildx vertex. A vertex is a unit of work BuildKit reports on: a Dockerfile instruction, the context transfer, a metadata lookup, the export to the registry.

Only the ones with an ordinal ([build 5/9]) are the operator's own steps — the rest are BuildKit's own bookkeeping, and counting them would make "cached steps 9 of 22" say something nobody asked.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, kind: :other, name: nil) ⇒ Step

Returns a new instance of Step.



22
23
24
25
26
27
# File 'lib/dash/build/step.rb', line 22

def initialize(number, kind: :other, name: nil)
  @number = number
  @kind = kind
  @name = name
  @cached = false
end

Instance Attribute Details

#bytes ⇒ Object

Returns the value of attribute bytes.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def bytes
  @bytes
end

#cached ⇒ Object

Returns the value of attribute cached.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def cached
  @cached
end

#error ⇒ Object

Returns the value of attribute error.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def error
  @error
end

#instruction ⇒ Object

Returns the value of attribute instruction.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def instruction
  @instruction
end

#kind ⇒ Object

Returns the value of attribute kind.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def kind
  @kind
end

#name ⇒ Object

Returns the value of attribute name.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def name
  @name
end

#number ⇒ Object (readonly)

Returns the value of attribute number.



8
9
10
# File 'lib/dash/build/step.rb', line 8

def number
  @number
end

#ordinal ⇒ Object

Returns the value of attribute ordinal.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def ordinal
  @ordinal
end

#platform ⇒ Object

Returns the value of attribute platform.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def platform
  @platform
end

#seconds ⇒ Object

Returns the value of attribute seconds.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def seconds
  @seconds
end

#stage ⇒ Object

Returns the value of attribute stage.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def stage
  @stage
end

#steps_in_stage ⇒ Object

Returns the value of attribute steps_in_stage.



9
10
11
# File 'lib/dash/build/step.rb', line 9

def steps_in_stage
  @steps_in_stage
end

Class Method Details

.from_h(step) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/dash/build/step.rb', line 11

def self.from_h(step)
  step = step.transform_keys(&:to_sym)

  new(step[:number], kind: step[:kind]&.to_sym || :other, name: step[:label]).tap do |rebuilt|
    rebuilt.platform, rebuilt.stage = step[:platform], step[:stage]
    rebuilt.ordinal, rebuilt.steps_in_stage = step[:ordinal], step[:steps_in_stage]
    rebuilt.instruction, rebuilt.seconds = step[:instruction], step[:seconds]
    rebuilt.cached, rebuilt.bytes, rebuilt.error = !!step[:cached], step[:bytes], step[:error]
  end
end

Instance Method Details

#dockerfile_step? ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dash/build/step.rb', line 36

def dockerfile_step?
  !ordinal.nil?
end

#label ⇒ Object

What buildx itself printed for this vertex, minus the platform prefix it adds on a multi-platform build — the operator matches these against their Dockerfile, and the platform is already its own column in the data.



32
33
34
# File 'lib/dash/build/step.rb', line 32

def label
  ordinal ? "[#{[ stage, "#{ordinal}/#{steps_in_stage}" ].compact.join(" ")}] #{instruction}" : name.to_s
end

#to_h ⇒ Object

label is here for whatever reads the JSON — it is the string buildx printed and the one a human matches against their Dockerfile — and the parts it is built from are here so #from_h can rebuild it rather than trusting a field a hand-edited file may disagree with.



44
45
46
47
48
# File 'lib/dash/build/step.rb', line 44

def to_h
  { number: number, kind: kind, label: label, platform: platform, stage: stage, ordinal: ordinal,
    steps_in_stage: steps_in_stage, instruction: instruction, seconds: seconds, cached: cached,
    bytes: bytes, error: error }
end