MCPcopy Create free account
hub / github.com/docker/buildx / testBuildPolicyConfigFlags

Function testBuildPolicyConfigFlags

tests/policy_build.go:1196–1342  ·  view source on GitHub ↗
(t *testing.T, sb integration.Sandbox)

Source from the content-addressed store, hash-verified

1194}
1195
1196func testBuildPolicyConfigFlags(t *testing.T, sb integration.Sandbox) {
1197 skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+")
1198
1199 dockerfile := []byte("FROM busybox:latest\nRUN echo policy-flags\n")
1200 defaultPolicy := []byte(`
1201package docker
1202
1203default allow = false
1204
1205allow if input.env.args["DEFAULT_OK"] == "1"
1206
1207decision := {"allow": allow}
1208`)
1209 extraPolicy := []byte(`
1210package docker
1211
1212default allow = false
1213
1214allow if input.env.labels["com.example.extra"] == "1"
1215
1216decision := {"allow": allow}
1217`)
1218 denyPolicy := []byte(`
1219package docker
1220
1221default allow = false
1222
1223decision := {"allow": allow}
1224`)
1225
1226 t.Run("additional-policy-requires-default", func(t *testing.T) {
1227 dir := tmpdir(
1228 t,
1229 fstest.CreateFile("Dockerfile", dockerfile, 0600),
1230 fstest.CreateFile("Dockerfile.rego", defaultPolicy, 0600),
1231 fstest.CreateFile("extra.rego", extraPolicy, 0600),
1232 )
1233 extraPath := filepath.Join(dir, "extra.rego")
1234
1235 cmd := buildxCmd(sb, withDir(dir), withArgs(
1236 "build",
1237 "--progress=plain",
1238 "--policy", "filename="+extraPath,
1239 "--build-arg", "DEFAULT_OK=1",
1240 "--label", "com.example.extra=1",
1241 "--output=type=cacheonly",
1242 dir,
1243 ))
1244 out, err := cmd.CombinedOutput()
1245 require.NoError(t, err, string(out))
1246
1247 cmd = buildxCmd(sb, withDir(dir), withArgs(
1248 "build",
1249 "--progress=plain",
1250 "--policy", "filename="+extraPath,
1251 "--label", "com.example.extra=1",
1252 "--output=type=cacheonly",
1253 dir,

Callers

nothing calls this directly

Calls 7

skipNoCompatBuildKitFunction · 0.85
tmpdirFunction · 0.85
buildxCmdFunction · 0.85
withDirFunction · 0.85
withArgsFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…