build: set target to local state

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-09-12 19:46:56 +02:00
parent cc6957d1cc
commit 2134a1e104
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
3 changed files with 9 additions and 12 deletions

View File

@ -423,6 +423,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
}
so := client.SolveOpt{
Ref: identity.NewID(),
Frontend: "dockerfile.v0",
FrontendAttrs: map[string]string{},
LocalDirs: map[string]string{},
@ -665,12 +666,6 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
so.FrontendAttrs["ulimit"] = ulimits
}
// remember local state like directory path that is not sent to buildkit
so.Ref = identity.NewID()
if err := saveLocalState(so, opt, node, configDir); err != nil {
return nil, nil, err
}
return &so, releaseF, nil
}
@ -748,6 +743,9 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
if err != nil {
return nil, err
}
if err := saveLocalState(so, k, opt, node, configDir); err != nil {
return nil, err
}
for k, v := range gitattrs {
so.FrontendAttrs[k] = v
}

View File

@ -8,15 +8,13 @@ import (
"github.com/moby/buildkit/client"
)
func saveLocalState(so client.SolveOpt, opt Options, node builder.Node, configDir string) error {
func saveLocalState(so *client.SolveOpt, target string, opts Options, node builder.Node, configDir string) error {
var err error
if so.Ref == "" {
return nil
}
lp := opt.Inputs.ContextPath
dp := opt.Inputs.DockerfilePath
lp := opts.Inputs.ContextPath
dp := opts.Inputs.DockerfilePath
if lp != "" || dp != "" {
if lp != "" {
lp, err = filepath.Abs(lp)
@ -35,12 +33,12 @@ func saveLocalState(so client.SolveOpt, opt Options, node builder.Node, configDi
return err
}
if err := ls.SaveRef(node.Builder, node.Name, so.Ref, localstate.State{
Target: target,
LocalPath: lp,
DockerfilePath: dp,
}); err != nil {
return err
}
}
return nil
}

View File

@ -12,6 +12,7 @@ import (
const refsDir = "refs"
type State struct {
Target string
LocalPath string
DockerfilePath string
}