Skip to content

Commit

Permalink
Review naming
Browse files Browse the repository at this point in the history
Add buildInfo to dispatchState

Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Aug 16, 2021
1 parent a962b0e commit e9767fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
15 changes: 6 additions & 9 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
}
}
if !isScratch {
img.BuildInfo, _ = json.Marshal(exptypes.BuildInfo{
d.buildInfo = &exptypes.BuildInfo{
Type: exptypes.BuildInfoTypeImage,
Ref: origName,
Alias: ref.String(),
Pin: dgst.String(),
})
}
}
d.image = img
}
Expand Down Expand Up @@ -335,13 +335,9 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
continue
}

// Collect build dependencies
if len(d.image.BuildInfo) > 0 {
var bi exptypes.BuildInfo
if err = json.Unmarshal(d.image.BuildInfo, &bi); err != nil {
return nil, nil, err
}
buildInfos = append(buildInfos, bi)
// collect build dependencies
if d.buildInfo != nil {
buildInfos = append(buildInfos, *d.buildInfo)
}

if d.base != nil {
Expand Down Expand Up @@ -611,6 +607,7 @@ type dispatchState struct {
cmdIndex int
cmdTotal int
prefixPlatform bool
buildInfo *exptypes.BuildInfo
}

type dispatchStates struct {
Expand Down
14 changes: 7 additions & 7 deletions solver/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type ResolveOpFunc func(Vertex, Builder) (Op, error)

type Builder interface {
Build(ctx context.Context, e Edge) (CachedResult, BuildInfoResult, error)
Build(ctx context.Context, e Edge) (CachedResult, BuildInfo, error)
InContext(ctx context.Context, f func(ctx context.Context, g session.Group) error) error
EachValue(ctx context.Context, key string, fn func(interface{}) error) error
}
Expand Down Expand Up @@ -197,8 +197,8 @@ type subBuilder struct {
exporters []ExportableCacheKey
}

func (sb *subBuilder) Build(ctx context.Context, e Edge) (CachedResult, BuildInfoResult, error) {
// TODO: Handle BuildInfoResult from subbuild
func (sb *subBuilder) Build(ctx context.Context, e Edge) (CachedResult, BuildInfo, error) {
// TODO: Handle BuildInfo from subbuild
res, err := sb.solver.subBuild(ctx, e, sb.vtx)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -496,7 +496,7 @@ func (jl *Solver) deleteIfUnreferenced(k digest.Digest, st *state) {
}
}

func (j *Job) Build(ctx context.Context, e Edge) (CachedResult, BuildInfoResult, error) {
func (j *Job) Build(ctx context.Context, e Edge) (CachedResult, BuildInfo, error) {
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
j.span = span
}
Expand All @@ -512,13 +512,13 @@ func (j *Job) Build(ctx context.Context, e Edge) (CachedResult, BuildInfoResult,
return nil, nil, err
}

return res, j.mergeBuildInfo(ctx, e), nil
return res, j.walkBuildInfo(ctx, e), nil
}

func (j *Job) mergeBuildInfo(ctx context.Context, e Edge) BuildInfoResult {
func (j *Job) walkBuildInfo(ctx context.Context, e Edge) BuildInfo {
j.list.mu.Lock()
defer j.list.mu.Unlock()
bi := make(BuildInfoResult)
bi := make(BuildInfo)
// FIXME: Walking should start from e
for _, st := range j.list.actives {
st.mu.Lock()
Expand Down
10 changes: 5 additions & 5 deletions solver/llbsolver/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type llbBridge struct {
sm *session.Manager
}

func (b *llbBridge) loadResult(ctx context.Context, def *pb.Definition, cacheImports []gw.CacheOptionsEntry) (solver.CachedResult, solver.BuildInfoResult, error) {
func (b *llbBridge) loadResult(ctx context.Context, def *pb.Definition, cacheImports []gw.CacheOptionsEntry) (solver.CachedResult, solver.BuildInfo, error) {
w, err := b.resolveWorker()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -136,13 +136,13 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
}

type resultProxy struct {
cb func(context.Context) (solver.CachedResult, solver.BuildInfoResult, error)
cb func(context.Context) (solver.CachedResult, solver.BuildInfo, error)
def *pb.Definition
g flightcontrol.Group
mu sync.Mutex
released bool
v solver.CachedResult
bi solver.BuildInfoResult
bi solver.BuildInfo
err error
errResults []solver.Result
}
Expand All @@ -151,7 +151,7 @@ func newResultProxy(b *llbBridge, req frontend.SolveRequest) *resultProxy {
rp := &resultProxy{
def: req.Definition,
}
rp.cb = func(ctx context.Context) (solver.CachedResult, solver.BuildInfoResult, error) {
rp.cb = func(ctx context.Context) (solver.CachedResult, solver.BuildInfo, error) {
res, bi, err := b.loadResult(ctx, req.Definition, req.CacheImports)
var ee *llberrdefs.ExecError
if errors.As(err, &ee) {
Expand All @@ -171,7 +171,7 @@ func (rp *resultProxy) Definition() *pb.Definition {
return rp.def
}

func (rp *resultProxy) BuildInfo() solver.BuildInfoResult {
func (rp *resultProxy) BuildInfo() solver.BuildInfo {
return rp.bi
}

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

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

dtbi, err := patchBuildInfo(ctx, res, inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, k)])
dtbi, err := mergeBuildInfo(ctx, res, inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, k)])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -290,15 +290,15 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
}, nil
}

// patchBuildInfo fixes and solved build info from image config
// moby.buildkit.buildinfo.v0
func patchBuildInfo(ctx context.Context, res solver.ResultProxy, dtic []byte) ([]byte, error) {
// mergeBuildInfo combines and fixes build info from image config
// key moby.buildkit.buildinfo.v0.
func mergeBuildInfo(ctx context.Context, res solver.ResultProxy, dtic []byte) ([]byte, error) {
icbi, err := imageConfigBuildInfo(dtic)
if err != nil {
bklog.G(ctx).Error(err)
}

// Iterate and patch build sources
// Iterate and combine build sources
mbis := map[string]exptypes.BuildInfo{}
for srcs, di := range res.BuildInfo() {
src, err := source.FromString(srcs)
Expand Down
8 changes: 5 additions & 3 deletions solver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type ResultProxy interface {
Result(context.Context) (CachedResult, error)
Release(context.Context) error
Definition() *pb.Definition
BuildInfo() BuildInfoResult
BuildInfo() BuildInfo
}

// CacheExportMode is the type for setting cache exporting modes
Expand Down Expand Up @@ -192,11 +192,13 @@ type CacheMap struct {
// the cache. Opts should not have any impact on the computed cache key.
Opts CacheOpts

// BuildInfo contains solved build dependencies.
// BuildInfo contains build dependencies that will be set from source
// operation.
BuildInfo map[string]string
}

type BuildInfoResult map[string]string
// BuildInfo contains solved build dependencies.
type BuildInfo map[string]string

// ExportableCacheKey is a cache key connected with an exporter that can export
// a chain of cacherecords pointing to that key
Expand Down

0 comments on commit e9767fb

Please sign in to comment.