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 4, 2022
1 parent 1c9d13d commit 6c3abec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions frontend/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/moby/buildkit/solver"
)

const MetadataFrontendAttrsKey = "internal.frontend.attrs"

type Result struct {
Ref solver.ResultProxy
Refs map[string]solver.ResultProxy
Expand Down
16 changes: 13 additions & 3 deletions solver/llbsolver/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package llbsolver

import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -142,8 +143,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 +155,19 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
return nil, err
}
} else {
return &frontend.Result{}, nil
res = &frontend.Result{}
}

if res.Metadata == nil {
res.Metadata = make(map[string][]byte)
}

attrs, err := json.Marshal(req.FrontendOpt)
if err != nil {
return nil, err
}
res.Metadata[frontend.MetadataFrontendAttrsKey] = attrs

return
}

Expand Down
5 changes: 2 additions & 3 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,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.Frontend, inp.Metadata[frontend.MetadataFrontendAttrsKey], res.BuildSources(), inp.Metadata[exptypes.ExporterImageConfigKey])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,7 +206,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.Frontend, inp.Metadata[frontend.MetadataFrontendAttrsKey], res.BuildSources(), inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, k)])
if err != nil {
return nil, err
}
Expand Down
13 changes: 9 additions & 4 deletions util/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/docker/distribution/reference"
"github.com/moby/buildkit/frontend"
"github.com/moby/buildkit/source"
binfotypes "github.com/moby/buildkit/util/buildinfo/types"
"github.com/moby/buildkit/util/urlutil"
Expand All @@ -26,7 +25,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, frontend string, buildAttrs []byte, buildSources map[string]string, imageConfig []byte) ([]byte, error) {
icbi, err := FromImageConfig(imageConfig)
if err != nil {
return nil, err
Expand All @@ -35,9 +34,15 @@ func Encode(ctx context.Context, req frontend.SolveRequest, buildSources map[str
if err != nil {
return nil, err
}
attrs := make(map[string]string)
if buildAttrs != nil {
if err = json.Unmarshal(buildAttrs, &attrs); err != nil {
return nil, err
}
}
return json.Marshal(binfotypes.BuildInfo{
Frontend: req.Frontend,
Attrs: filterAttrs(req.FrontendOpt),
Frontend: frontend,
Attrs: filterAttrs(attrs),
Sources: srcs,
})
}
Expand Down

0 comments on commit 6c3abec

Please sign in to comment.