Skip to content

Commit

Permalink
buildinfo: set frontend attrs to bridge result
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 3, 2022
1 parent 94e9bbd commit 6b4d2bc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions frontend/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Result struct {
Ref solver.ResultProxy
Refs map[string]solver.ResultProxy
Metadata map[string][]byte
Attrs map[string]string
}

func (r *Result) EachRef(fn func(solver.ResultProxy) error) (err error) {
Expand Down
6 changes: 3 additions & 3 deletions solver/llbsolver/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
if req.Definition != nil && req.Definition.Def != nil {
res = &frontend.Result{Ref: newResultProxy(b, req)}
if req.Evaluate {
_, err := res.Ref.Result(ctx)
return res, err
_, err = res.Ref.Result(ctx)
}
} else if req.Frontend != "" {
f, ok := b.frontends[req.Frontend]
Expand All @@ -155,9 +154,10 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
return nil, err
}
} else {
return &frontend.Result{}, nil
res = &frontend.Result{}
}

res.Attrs = req.FrontendOpt
return
}

Expand Down
6 changes: 3 additions & 3 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro

var exporterResponse map[string]string
if e := exp.Exporter; e != nil {
frontendAttrs := res.Attrs
inp := exporter.Source{
Metadata: res.Metadata,
}
Expand All @@ -174,8 +175,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
return nil, errors.Errorf("invalid reference: %T", r.Sys())
}
inp.Ref = workerRef.ImmutableRef

dtbi, err := buildinfo.Encode(ctx, req, res.BuildSources(), inp.Metadata[exptypes.ExporterImageConfigKey])
dtbi, err := buildinfo.Encode(ctx, req, frontendAttrs, res.BuildSources(), inp.Metadata[exptypes.ExporterImageConfigKey])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
}
m[k] = workerRef.ImmutableRef

dtbi, err := buildinfo.Encode(ctx, req, res.BuildSources(), inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, k)])
dtbi, err := buildinfo.Encode(ctx, req, frontendAttrs, res.BuildSources(), inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, k)])
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions util/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Decode(enc string) (bi binfotypes.BuildInfo, _ error) {
}

// Encode encodes build info.
func Encode(ctx context.Context, req frontend.SolveRequest, buildSources map[string]string, imageConfig []byte) ([]byte, error) {
func Encode(ctx context.Context, req frontend.SolveRequest, buildAttrs map[string]string, buildSources map[string]string, imageConfig []byte) ([]byte, error) {
icbi, err := FromImageConfig(imageConfig)
if err != nil {
return nil, err
Expand All @@ -37,7 +37,7 @@ func Encode(ctx context.Context, req frontend.SolveRequest, buildSources map[str
}
return json.Marshal(binfotypes.BuildInfo{
Frontend: req.Frontend,
Attrs: filterAttrs(req.FrontendOpt),
Attrs: filterAttrs(buildAttrs),
Sources: srcs,
})
}
Expand Down

0 comments on commit 6b4d2bc

Please sign in to comment.