Skip to content

Commit

Permalink
Add support for progress groups.
Browse files Browse the repository at this point in the history
This allows clients to specify that LLB states should be grouped in
progress output under a custom name. Status updates for all vertexes in
the group will show up under a single vertex in the output.

The intended use cases are for Dockerfile COPY's that use MergeOp as a
backend and for grouping some other internal vertexes during frontend
builds.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
  • Loading branch information
sipsma committed Feb 3, 2022
1 parent 40a9ecc commit bec262a
Show file tree
Hide file tree
Showing 17 changed files with 792 additions and 333 deletions.
315 changes: 188 additions & 127 deletions api/services/control/control.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/services/control/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ message Vertex {
google.protobuf.Timestamp started = 5 [(gogoproto.stdtime) = true ];
google.protobuf.Timestamp completed = 6 [(gogoproto.stdtime) = true ];
string error = 7; // typed errors?
pb.ProgressGroup progressGroup = 8;
}

message VertexStatus {
Expand Down
1 change: 1 addition & 0 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ func (cm *cacheManager) createMergeRef(ctx context.Context, parents parentRefs,
}
if len(parents.mergeParents) == 1 {
// merge of 1 thing is that thing
parents.mergeParents[0].progress = pg
return parents.mergeParents[0], nil
}

Expand Down
15 changes: 8 additions & 7 deletions client/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
)

type Vertex struct {
Digest digest.Digest
Inputs []digest.Digest
Name string
Started *time.Time
Completed *time.Time
Cached bool
Error string
Digest digest.Digest
Inputs []digest.Digest
Name string
Started *time.Time
Completed *time.Time
Cached bool
Error string
ProgressGroup *pb.ProgressGroup
}

type VertexStatus struct {
Expand Down
10 changes: 10 additions & 0 deletions client/llb/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ func mergeMetadata(m1, m2 pb.OpMetadata) pb.OpMetadata {
m1.Caps[k] = true
}

if m2.ProgressGroup != nil {
m1.ProgressGroup = m2.ProgressGroup
}

return m1
}

Expand Down Expand Up @@ -594,6 +598,12 @@ func LocalUniqueID(v string) ConstraintsOpt {
})
}

func ProgressGroup(id, name string) ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
c.Metadata.ProgressGroup = &pb.ProgressGroup{Id: id, Name: name}
})
}

var (
LinuxAmd64 = Platform(ocispecs.Platform{OS: "linux", Architecture: "amd64"})
LinuxArmhf = Platform(ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v7"})
Expand Down
15 changes: 8 additions & 7 deletions client/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,14 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
s := SolveStatus{}
for _, v := range resp.Vertexes {
s.Vertexes = append(s.Vertexes, &Vertex{
Digest: v.Digest,
Inputs: v.Inputs,
Name: v.Name,
Started: v.Started,
Completed: v.Completed,
Error: v.Error,
Cached: v.Cached,
Digest: v.Digest,
Inputs: v.Inputs,
Name: v.Name,
Started: v.Started,
Completed: v.Completed,
Error: v.Error,
Cached: v.Cached,
ProgressGroup: v.ProgressGroup,
})
}
for _, v := range resp.Statuses {
Expand Down
15 changes: 8 additions & 7 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,14 @@ func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Con
sr := controlapi.StatusResponse{}
for _, v := range ss.Vertexes {
sr.Vertexes = append(sr.Vertexes, &controlapi.Vertex{
Digest: v.Digest,
Inputs: v.Inputs,
Name: v.Name,
Started: v.Started,
Completed: v.Completed,
Error: v.Error,
Cached: v.Cached,
Digest: v.Digest,
Inputs: v.Inputs,
Name: v.Name,
Started: v.Started,
Completed: v.Completed,
Error: v.Error,
Cached: v.Cached,
ProgressGroup: v.ProgressGroup,
})
}
for _, v := range ss.Statuses {
Expand Down
7 changes: 4 additions & 3 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,10 @@ func initClientVertex(v Vertex) client.Vertex {
inputDigests = append(inputDigests, inp.Vertex.Digest())
}
return client.Vertex{
Inputs: inputDigests,
Name: v.Name(),
Digest: v.Digest(),
Inputs: inputDigests,
Name: v.Name(),
Digest: v.Digest(),
ProgressGroup: v.Options().ProgressGroup,
}
}

Expand Down
1 change: 1 addition & 0 deletions solver/llbsolver/ops/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (d *diffOp) CacheMap(ctx context.Context, group session.Group, index int) (
WriterFactory: progress.FromContext(ctx),
Digest: d.vtx.Digest(),
Name: d.vtx.Name(),
ProgressGroup: d.vtx.Options().ProgressGroup,
}
cm.Opts[cache.ProgressKey{}] = d.pg

Expand Down
1 change: 1 addition & 0 deletions solver/llbsolver/ops/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (m *mergeOp) CacheMap(ctx context.Context, group session.Group, index int)
WriterFactory: progress.FromContext(ctx),
Digest: m.vtx.Digest(),
Name: m.vtx.Name(),
ProgressGroup: m.vtx.Options().ProgressGroup,
}
cm.Opts[cache.ProgressKey{}] = m.pg

Expand Down
1 change: 1 addition & 0 deletions solver/llbsolver/vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func newVertex(dgst digest.Digest, op *pb.Op, opMeta *pb.OpMetadata, load func(d
if opMeta.ExportCache != nil {
opt.ExportCache = &opMeta.ExportCache.Value
}
opt.ProgressGroup = opMeta.ProgressGroup
}
for _, fn := range opts {
if err := fn(op, opMeta, &opt); err != nil {
Expand Down
Loading

0 comments on commit bec262a

Please sign in to comment.