localstate: remove definition and inputs fields from group

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-02-04 21:55:35 +01:00
parent ef99381eab
commit f5196f1167
4 changed files with 92 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"sync"
"github.com/docker/buildx/util/confutil"
@ -14,6 +15,7 @@ import (
)
const (
version = 2
refsDir = "refs"
groupDir = "__group__"
)
@ -31,12 +33,8 @@ type State struct {
}
type StateGroup struct {
// Definition is the raw representation of the group (bake definition)
Definition []byte
// Targets are the targets invoked
Targets []string `json:",omitempty"`
// Inputs are the user inputs (bake overrides)
Inputs []string `json:",omitempty"`
// Refs are used to track all the refs that belong to the same group
Refs []string
}
@ -52,9 +50,7 @@ func New(cfg *confutil.Config) (*LocalState, error) {
if err := cfg.MkdirAll(refsDir, 0700); err != nil {
return nil, err
}
return &LocalState{
cfg: cfg,
}, nil
return &LocalState{cfg: cfg}, nil
}
func (ls *LocalState) ReadRef(builderName, nodeName, id string) (*State, error) {
@ -87,8 +83,12 @@ func (ls *LocalState) SaveRef(builderName, nodeName, id string, st State) error
return ls.cfg.AtomicWriteFile(filepath.Join(refDir, id), dt, 0644)
}
func (ls *LocalState) GroupDir() string {
return filepath.Join(ls.cfg.Dir(), refsDir, groupDir)
}
func (ls *LocalState) ReadGroup(id string) (*StateGroup, error) {
dt, err := os.ReadFile(filepath.Join(ls.cfg.Dir(), refsDir, groupDir, id))
dt, err := os.ReadFile(filepath.Join(ls.GroupDir(), id))
if err != nil {
return nil, err
}
@ -208,7 +208,7 @@ func (ls *LocalState) removeGroup(id string) error {
if id == "" {
return errors.Errorf("group ref empty")
}
f := filepath.Join(ls.cfg.Dir(), refsDir, groupDir, id)
f := filepath.Join(ls.GroupDir(), id)
if _, err := os.Lstat(f); err != nil {
if !os.IsNotExist(err) {
return err
@ -230,3 +230,16 @@ func (ls *LocalState) validate(builderName, nodeName, id string) error {
}
return nil
}
func (ls *LocalState) readVersion() int {
if vdt, err := os.ReadFile(filepath.Join(ls.cfg.Dir(), refsDir, "version")); err == nil {
if v, err := strconv.Atoi(string(vdt)); err == nil {
return v
}
}
return 1
}
func (ls *LocalState) writeVersion(version int) error {
return ls.cfg.AtomicWriteFile(filepath.Join(refsDir, "version"), []byte(strconv.Itoa(version)), 0600)
}