Skip to content

Commit b62fc30

Browse files
committed
build: resolve policy files from context state and unified FS
Support remote context policy files via resolved context state and cwd:// override. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 5830f90 commit b62fc30

File tree

7 files changed

+897
-153
lines changed

7 files changed

+897
-153
lines changed

build/build.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/fs"
1211
"maps"
1312
"os"
1413
"slices"
@@ -22,7 +21,6 @@ import (
2221
noderesolver "github.com/docker/buildx/build/resolver"
2322
"github.com/docker/buildx/builder"
2423
"github.com/docker/buildx/driver"
25-
"github.com/docker/buildx/policy"
2624
"github.com/docker/buildx/util/buildflags"
2725
"github.com/docker/buildx/util/confutil"
2826
"github.com/docker/buildx/util/desktop"
@@ -120,13 +118,24 @@ type Inputs struct {
120118
policy *policyOpt
121119
}
122120

123-
type policyOpt struct {
124-
Files []policy.File
125-
FS func() (fs.StatFS, func() error, error)
121+
type policyFileSpec struct {
122+
Filename string
123+
Optional bool
124+
Data []byte
125+
}
126+
127+
type policyEvalOpt struct {
126128
Strict bool
127129
LogLevel *logrus.Level
128130
}
129131

132+
type policyOpt struct {
133+
Files []policyFileSpec
134+
ContextDir string
135+
ContextState *llb.State
136+
policyEvalOpt
137+
}
138+
130139
func withPolicyConfig(defaultPolicy policyOpt, configs []buildflags.PolicyConfig) ([]policyOpt, error) {
131140
if len(configs) == 0 {
132141
if len(defaultPolicy.Files) == 0 {
@@ -176,7 +185,10 @@ func withPolicyConfig(defaultPolicy policyOpt, configs []buildflags.PolicyConfig
176185
}
177186

178187
opt := policyOpt{
179-
Files: cfg.Files,
188+
Files: make([]policyFileSpec, 0, len(cfg.Files)),
189+
}
190+
for _, f := range cfg.Files {
191+
opt.Files = append(opt.Files, policyFileSpec{Filename: f.Filename})
180192
}
181193
if last.Strict != nil {
182194
opt.Strict = *last.Strict
@@ -190,7 +202,8 @@ func withPolicyConfig(defaultPolicy policyOpt, configs []buildflags.PolicyConfig
190202
if cfg.LogLevel != nil {
191203
opt.LogLevel = cfg.LogLevel
192204
}
193-
opt.FS = defaultPolicy.FS
205+
opt.ContextDir = defaultPolicy.ContextDir
206+
opt.ContextState = defaultPolicy.ContextState
194207
out = append(out, opt)
195208
}
196209

0 commit comments

Comments
 (0)