Skip to content

Commit 910e526

Browse files
authored
Merge pull request moby#3711 from crazy-max/test-feature-envs
integration: enforce features compat through env vars
2 parents 2a0dd4b + 5102c5a commit 910e526

File tree

6 files changed

+105
-54
lines changed

6 files changed

+105
-54
lines changed

client/client_test.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func newContainerd(cdAddress string) (*containerd.Client, error) {
245245

246246
// moby/buildkit#1336
247247
func testCacheExportCacheKeyLoop(t *testing.T, sb integration.Sandbox) {
248-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
248+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheBackendLocal)
249249
c, err := New(sb.Context(), sb.Address())
250250
require.NoError(t, err)
251251
defer c.Close()
@@ -3747,7 +3747,7 @@ func testBuildPushAndValidate(t *testing.T, sb integration.Sandbox) {
37473747
}
37483748

37493749
func testStargzLazyRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
3750-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
3750+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendRegistry)
37513751
requiresLinux(t)
37523752
cdAddress := sb.ContainerdAddress()
37533753
if cdAddress == "" || sb.Snapshotter() != "stargz" {
@@ -3945,7 +3945,12 @@ func testStargzLazyRegistryCacheImportExport(t *testing.T, sb integration.Sandbo
39453945
}
39463946

39473947
func testStargzLazyInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
3948-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
3948+
integration.CheckFeatureCompat(t, sb,
3949+
integration.FeatureCacheExport,
3950+
integration.FeatureCacheImport,
3951+
integration.FeatureCacheBackendInline,
3952+
integration.FeatureCacheBackendRegistry,
3953+
)
39493954
requiresLinux(t)
39503955
cdAddress := sb.ContainerdAddress()
39513956
if cdAddress == "" || sb.Snapshotter() != "stargz" {
@@ -4392,7 +4397,7 @@ func testLazyImagePush(t *testing.T, sb integration.Sandbox) {
43924397
}
43934398

43944399
func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
4395-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4400+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheBackendLocal)
43964401
c, err := New(sb.Context(), sb.Address())
43974402
require.NoError(t, err)
43984403
defer c.Close()
@@ -4451,7 +4456,7 @@ func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
44514456
}
44524457

44534458
func testCacheExportIgnoreError(t *testing.T, sb integration.Sandbox) {
4454-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4459+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheBackendLocal)
44554460
c, err := New(sb.Context(), sb.Address())
44564461
require.NoError(t, err)
44574462
defer c.Close()
@@ -4558,7 +4563,7 @@ func testCacheExportIgnoreError(t *testing.T, sb integration.Sandbox) {
45584563
}
45594564

45604565
func testUncompressedLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
4561-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4566+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendLocal)
45624567
dir := t.TempDir()
45634568
im := CacheOptionsEntry{
45644569
Type: "local",
@@ -4578,7 +4583,7 @@ func testUncompressedLocalCacheImportExport(t *testing.T, sb integration.Sandbox
45784583
}
45794584

45804585
func testUncompressedRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
4581-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4586+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendRegistry)
45824587
registry, err := sb.NewRegistry()
45834588
if errors.Is(err, integration.ErrRequirements) {
45844589
t.Skip(err.Error())
@@ -4603,7 +4608,7 @@ func testUncompressedRegistryCacheImportExport(t *testing.T, sb integration.Sand
46034608
}
46044609

46054610
func testZstdLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
4606-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4611+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendLocal)
46074612
dir := t.TempDir()
46084613
im := CacheOptionsEntry{
46094614
Type: "local",
@@ -4624,7 +4629,7 @@ func testZstdLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
46244629
}
46254630

46264631
func testZstdRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
4627-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4632+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendRegistry)
46284633
registry, err := sb.NewRegistry()
46294634
if errors.Is(err, integration.ErrRequirements) {
46304635
t.Skip(err.Error())
@@ -4712,7 +4717,7 @@ func testBasicCacheImportExport(t *testing.T, sb integration.Sandbox, cacheOptio
47124717
}
47134718

47144719
func testBasicRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
4715-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4720+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendRegistry)
47164721
registry, err := sb.NewRegistry()
47174722
if errors.Is(err, integration.ErrRequirements) {
47184723
t.Skip(err.Error())
@@ -4729,7 +4734,7 @@ func testBasicRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
47294734
}
47304735

47314736
func testMultipleRegistryCacheImportExport(t *testing.T, sb integration.Sandbox) {
4732-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4737+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendRegistry)
47334738
registry, err := sb.NewRegistry()
47344739
if errors.Is(err, integration.ErrRequirements) {
47354740
t.Skip(err.Error())
@@ -4752,7 +4757,7 @@ func testMultipleRegistryCacheImportExport(t *testing.T, sb integration.Sandbox)
47524757
}
47534758

47544759
func testBasicLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
4755-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4760+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendLocal)
47564761
dir := t.TempDir()
47574762
im := CacheOptionsEntry{
47584763
Type: "local",
@@ -4770,7 +4775,7 @@ func testBasicLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
47704775
}
47714776

47724777
func testBasicS3CacheImportExport(t *testing.T, sb integration.Sandbox) {
4773-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4778+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendS3)
47744779

47754780
opts := integration.MinioOpts{
47764781
Region: "us-east-1",
@@ -4808,7 +4813,7 @@ func testBasicS3CacheImportExport(t *testing.T, sb integration.Sandbox) {
48084813
}
48094814

48104815
func testBasicAzblobCacheImportExport(t *testing.T, sb integration.Sandbox) {
4811-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4816+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendAzblob)
48124817

48134818
opts := integration.AzuriteOpts{
48144819
AccountName: "azblobcacheaccount",
@@ -4841,7 +4846,13 @@ func testBasicAzblobCacheImportExport(t *testing.T, sb integration.Sandbox) {
48414846
}
48424847

48434848
func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
4844-
integration.CheckFeatureCompat(t, sb, integration.FeatureDirectPush, integration.FeatureCacheImport)
4849+
integration.CheckFeatureCompat(t, sb,
4850+
integration.FeatureDirectPush,
4851+
integration.FeatureCacheExport,
4852+
integration.FeatureCacheImport,
4853+
integration.FeatureCacheBackendInline,
4854+
integration.FeatureCacheBackendRegistry,
4855+
)
48454856
requiresLinux(t)
48464857
registry, err := sb.NewRegistry()
48474858
if errors.Is(err, integration.ErrRequirements) {
@@ -5001,7 +5012,7 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
50015012
}
50025013

50035014
func testBasicGhaCacheImportExport(t *testing.T, sb integration.Sandbox) {
5004-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
5015+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendGha)
50055016
runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN")
50065017
cacheURL := os.Getenv("ACTIONS_CACHE_URL")
50075018
if runtimeToken == "" || cacheURL == "" {
@@ -5806,6 +5817,7 @@ func testProxyEnv(t *testing.T, sb integration.Sandbox) {
58065817
}
58075818

58085819
func testMergeOp(t *testing.T, sb integration.Sandbox) {
5820+
integration.CheckFeatureCompat(t, sb, integration.FeatureMergeDiff)
58095821
requiresLinux(t)
58105822

58115823
c, err := New(sb.Context(), sb.Address())
@@ -5918,7 +5930,7 @@ func testMergeOpCacheMax(t *testing.T, sb integration.Sandbox) {
59185930

59195931
func testMergeOpCache(t *testing.T, sb integration.Sandbox, mode string) {
59205932
t.Helper()
5921-
integration.CheckFeatureCompat(t, sb, integration.FeatureDirectPush)
5933+
integration.CheckFeatureCompat(t, sb, integration.FeatureDirectPush, integration.FeatureMergeDiff)
59225934
requiresLinux(t)
59235935

59245936
cdAddress := sb.ContainerdAddress()

client/mergediff_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ func (tc verifyContents) Name() string {
11871187
}
11881188

11891189
func (tc verifyContents) Run(t *testing.T, sb integration.Sandbox) {
1190+
integration.CheckFeatureCompat(t, sb, integration.FeatureMergeDiff)
11901191
if tc.skipOnRootless && sb.Rootless() {
11911192
t.Skip("rootless")
11921193
}

frontend/dockerfile/dockerfile_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ RUN [ "$(cat testfile)" == "contents0" ]
423423
}
424424

425425
func testExportCacheLoop(t *testing.T, sb integration.Sandbox) {
426-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
426+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheImport, integration.FeatureCacheBackendLocal)
427427
f := getFrontend(t, sb)
428428

429429
dockerfile := []byte(`
@@ -3952,7 +3952,12 @@ ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
39523952
}
39533953

39543954
func testCacheMultiPlatformImportExport(t *testing.T, sb integration.Sandbox) {
3955-
integration.CheckFeatureCompat(t, sb, integration.FeatureDirectPush)
3955+
integration.CheckFeatureCompat(t, sb,
3956+
integration.FeatureDirectPush,
3957+
integration.FeatureCacheExport,
3958+
integration.FeatureCacheBackendInline,
3959+
integration.FeatureCacheBackendRegistry,
3960+
)
39563961
f := getFrontend(t, sb)
39573962

39583963
registry, err := sb.NewRegistry()
@@ -4075,7 +4080,7 @@ COPY --from=base arch /
40754080
}
40764081

40774082
func testCacheImportExport(t *testing.T, sb integration.Sandbox) {
4078-
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4083+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport, integration.FeatureCacheBackendLocal)
40794084
f := getFrontend(t, sb)
40804085

40814086
registry, err := sb.NewRegistry()

hack/test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
7878
fi
7979

8080
if [ "$TEST_INTEGRATION" == 1 ]; then
81-
cid=$(docker create --rm -v /tmp $coverageVol --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...})
81+
cid=$(docker create --rm -v /tmp $coverageVol --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS -e BUILDKIT_TEST_ENABLE_FEATURES -e BUILDKIT_TEST_DISABLE_FEATURES ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...})
8282
if [ "$TEST_DOCKERD" = "1" ]; then
8383
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd
8484
fi
@@ -118,7 +118,7 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
118118

119119
if [ -s $tarout ]; then
120120
if [ "$release" = "mainline" ] || [ "$release" = "labs" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
121-
cid=$(docker create -v /tmp $coverageVol --rm --privileged --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
121+
cid=$(docker create -v /tmp $coverageVol --rm --privileged --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e BUILDKIT_TEST_ENABLE_FEATURES -e BUILDKIT_TEST_DISABLE_FEATURES -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
122122
docker cp $tarout $cid:/$release.tar
123123
if [ "$TEST_DOCKERD" = "1" ]; then
124124
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd

util/testutil/integration/dockerd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func InitDockerdWorker() {
2525
unsupported: []string{
2626
FeatureCacheExport,
2727
FeatureCacheImport,
28+
FeatureCacheBackendAzblob,
29+
FeatureCacheBackendGha,
30+
FeatureCacheBackendLocal,
31+
FeatureCacheBackendRegistry,
32+
FeatureCacheBackendS3,
2833
FeatureDirectPush,
2934
FeatureImageExporter,
3035
FeatureMultiCacheExport,

util/testutil/integration/sandbox.go

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ func (b backend) Snapshotter() string {
4646
}
4747

4848
func (b backend) isUnsupportedFeature(feature string) bool {
49+
if enabledFeatures := os.Getenv("BUILDKIT_TEST_ENABLE_FEATURES"); enabledFeatures != "" {
50+
for _, enabledFeature := range strings.Split(enabledFeatures, ",") {
51+
if feature == enabledFeature {
52+
return false
53+
}
54+
}
55+
}
56+
if disabledFeatures := os.Getenv("BUILDKIT_TEST_DISABLE_FEATURES"); disabledFeatures != "" {
57+
for _, disabledFeature := range strings.Split(disabledFeatures, ",") {
58+
if feature == disabledFeature {
59+
return true
60+
}
61+
}
62+
}
4963
for _, unsupportedFeature := range b.unsupportedFeatures {
5064
if feature == unsupportedFeature {
5165
return true
@@ -270,41 +284,55 @@ func printLogs(logs map[string]*bytes.Buffer, f func(args ...interface{})) {
270284
}
271285

272286
const (
273-
FeatureCacheExport = "cache export"
274-
FeatureCacheImport = "cache import"
275-
FeatureDirectPush = "direct push"
276-
FeatureFrontendOutline = "frontend outline"
277-
FeatureFrontendTargets = "frontend targets"
278-
FeatureImageExporter = "image exporter"
279-
FeatureInfo = "info"
280-
FeatureMultiCacheExport = "multi cache export"
281-
FeatureMultiPlatform = "multi-platform"
282-
FeatureOCIExporter = "oci exporter"
283-
FeatureOCILayout = "oci layout"
284-
FeatureProvenance = "provenance"
285-
FeatureSBOM = "sbom"
286-
FeatureSecurityMode = "security mode"
287-
FeatureSourceDateEpoch = "source date epoch"
288-
FeatureCNINetwork = "cni network"
287+
FeatureCacheExport = "cache_export"
288+
FeatureCacheImport = "cache_import"
289+
FeatureCacheBackendAzblob = "cache_backend_azblob"
290+
FeatureCacheBackendGha = "cache_backend_gha"
291+
FeatureCacheBackendInline = "cache_backend_inline"
292+
FeatureCacheBackendLocal = "cache_backend_local"
293+
FeatureCacheBackendRegistry = "cache_backend_registry"
294+
FeatureCacheBackendS3 = "cache_backend_s3"
295+
FeatureDirectPush = "direct_push"
296+
FeatureFrontendOutline = "frontend_outline"
297+
FeatureFrontendTargets = "frontend_targets"
298+
FeatureImageExporter = "image_exporter"
299+
FeatureInfo = "info"
300+
FeatureMergeDiff = "merge_diff"
301+
FeatureMultiCacheExport = "multi_cache_export"
302+
FeatureMultiPlatform = "multi_platform"
303+
FeatureOCIExporter = "oci_exporter"
304+
FeatureOCILayout = "oci_layout"
305+
FeatureProvenance = "provenance"
306+
FeatureSBOM = "sbom"
307+
FeatureSecurityMode = "security_mode"
308+
FeatureSourceDateEpoch = "source_date_epoch"
309+
FeatureCNINetwork = "cni_network"
289310
)
290311

291312
var features = map[string]struct{}{
292-
FeatureCacheExport: {},
293-
FeatureCacheImport: {},
294-
FeatureDirectPush: {},
295-
FeatureFrontendOutline: {},
296-
FeatureFrontendTargets: {},
297-
FeatureImageExporter: {},
298-
FeatureInfo: {},
299-
FeatureMultiCacheExport: {},
300-
FeatureMultiPlatform: {},
301-
FeatureOCIExporter: {},
302-
FeatureOCILayout: {},
303-
FeatureProvenance: {},
304-
FeatureSBOM: {},
305-
FeatureSecurityMode: {},
306-
FeatureSourceDateEpoch: {},
307-
FeatureCNINetwork: {},
313+
FeatureCacheExport: {},
314+
FeatureCacheImport: {},
315+
FeatureCacheBackendAzblob: {},
316+
FeatureCacheBackendGha: {},
317+
FeatureCacheBackendInline: {},
318+
FeatureCacheBackendLocal: {},
319+
FeatureCacheBackendRegistry: {},
320+
FeatureCacheBackendS3: {},
321+
FeatureDirectPush: {},
322+
FeatureFrontendOutline: {},
323+
FeatureFrontendTargets: {},
324+
FeatureImageExporter: {},
325+
FeatureInfo: {},
326+
FeatureMergeDiff: {},
327+
FeatureMultiCacheExport: {},
328+
FeatureMultiPlatform: {},
329+
FeatureOCIExporter: {},
330+
FeatureOCILayout: {},
331+
FeatureProvenance: {},
332+
FeatureSBOM: {},
333+
FeatureSecurityMode: {},
334+
FeatureSourceDateEpoch: {},
335+
FeatureCNINetwork: {},
308336
}
309337

310338
func CheckFeatureCompat(t *testing.T, sb Sandbox, reason ...string) {

0 commit comments

Comments
 (0)