mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:37:46 +08:00
build: move localstate logic
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
7b049b99c5
commit
cc6957d1cc
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
"github.com/docker/buildx/driver"
|
"github.com/docker/buildx/driver"
|
||||||
"github.com/docker/buildx/localstate"
|
|
||||||
"github.com/docker/buildx/util/desktop"
|
"github.com/docker/buildx/util/desktop"
|
||||||
"github.com/docker/buildx/util/dockerutil"
|
"github.com/docker/buildx/util/dockerutil"
|
||||||
"github.com/docker/buildx/util/imagetools"
|
"github.com/docker/buildx/util/imagetools"
|
||||||
@ -1649,43 +1648,6 @@ func noPrintFunc(opt map[string]Options) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveLocalState(so client.SolveOpt, opt Options, node builder.Node, configDir string) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if so.Ref == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lp := opt.Inputs.ContextPath
|
|
||||||
dp := opt.Inputs.DockerfilePath
|
|
||||||
if lp != "" || dp != "" {
|
|
||||||
if lp != "" {
|
|
||||||
lp, err = filepath.Abs(lp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if dp != "" {
|
|
||||||
dp, err = filepath.Abs(dp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ls, err := localstate.New(configDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := ls.SaveRef(node.Builder, node.Name, so.Ref, localstate.State{
|
|
||||||
LocalPath: lp,
|
|
||||||
DockerfilePath: dp,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadSourcePolicy reads a source policy from a file.
|
// ReadSourcePolicy reads a source policy from a file.
|
||||||
// The file path is taken from EXPERIMENTAL_BUILDKIT_SOURCE_POLICY env var.
|
// The file path is taken from EXPERIMENTAL_BUILDKIT_SOURCE_POLICY env var.
|
||||||
// if the env var is not set, this `returns nil, nil`
|
// if the env var is not set, this `returns nil, nil`
|
||||||
|
46
build/localstate.go
Normal file
46
build/localstate.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/docker/buildx/builder"
|
||||||
|
"github.com/docker/buildx/localstate"
|
||||||
|
"github.com/moby/buildkit/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func saveLocalState(so client.SolveOpt, opt Options, node builder.Node, configDir string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if so.Ref == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
lp := opt.Inputs.ContextPath
|
||||||
|
dp := opt.Inputs.DockerfilePath
|
||||||
|
if lp != "" || dp != "" {
|
||||||
|
if lp != "" {
|
||||||
|
lp, err = filepath.Abs(lp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if dp != "" {
|
||||||
|
dp, err = filepath.Abs(dp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ls, err := localstate.New(configDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ls.SaveRef(node.Builder, node.Name, so.Ref, localstate.State{
|
||||||
|
LocalPath: lp,
|
||||||
|
DockerfilePath: dp,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user