@@ -32,8 +32,8 @@ import (
32
32
33
33
func TestBuild (t * testing.T ) {
34
34
testutil .RequiresBuild (t )
35
+ testutil .RegisterBuildCacheCleanup (t )
35
36
base := testutil .NewBase (t )
36
- defer base .Cmd ("builder" , "prune" ).Run ()
37
37
imageName := testutil .Identifier (t )
38
38
defer base .Cmd ("rmi" , imageName ).Run ()
39
39
@@ -57,8 +57,8 @@ CMD ["echo", "nerdctl-build-test-string"]
57
57
58
58
func TestBuildIsShareableForCompatiblePlatform (t * testing.T ) {
59
59
testutil .RequiresBuild (t )
60
+ testutil .RegisterBuildCacheCleanup (t )
60
61
base := testutil .NewBase (t )
61
- defer base .Cmd ("builder" , "prune" ).Run ()
62
62
imageName := testutil .Identifier (t )
63
63
defer base .Cmd ("rmi" , imageName ).Run ()
64
64
@@ -87,8 +87,8 @@ CMD ["echo", "nerdctl-build-test-string"]
87
87
// This isn't currently supported by nerdctl with BuildKit OCI worker.
88
88
func TestBuildBaseImage (t * testing.T ) {
89
89
testutil .RequiresBuild (t )
90
+ testutil .RegisterBuildCacheCleanup (t )
90
91
base := testutil .NewBase (t )
91
- defer base .Cmd ("builder" , "prune" ).Run ()
92
92
imageName := testutil .Identifier (t )
93
93
defer base .Cmd ("rmi" , imageName ).Run ()
94
94
imageName2 := imageName + "-2"
@@ -122,8 +122,8 @@ CMD ["cat", "/hello2"]
122
122
func TestBuildFromContainerd (t * testing.T ) {
123
123
testutil .DockerIncompatible (t )
124
124
testutil .RequiresBuild (t )
125
+ testutil .RegisterBuildCacheCleanup (t )
125
126
base := testutil .NewBase (t )
126
- defer base .Cmd ("builder" , "prune" ).Run ()
127
127
imageName := testutil .Identifier (t )
128
128
defer base .Cmd ("rmi" , imageName ).Run ()
129
129
imageName2 := imageName + "-2"
@@ -152,8 +152,8 @@ CMD ["cat", "/hello2"]
152
152
153
153
func TestBuildFromStdin (t * testing.T ) {
154
154
testutil .RequiresBuild (t )
155
+ testutil .RegisterBuildCacheCleanup (t )
155
156
base := testutil .NewBase (t )
156
- defer base .Cmd ("builder" , "prune" ).Run ()
157
157
imageName := testutil .Identifier (t )
158
158
defer base .Cmd ("rmi" , imageName ).Run ()
159
159
@@ -166,8 +166,8 @@ CMD ["echo", "nerdctl-build-test-stdin"]
166
166
167
167
func TestBuildWithDockerfile (t * testing.T ) {
168
168
testutil .RequiresBuild (t )
169
+ testutil .RegisterBuildCacheCleanup (t )
169
170
base := testutil .NewBase (t )
170
- defer base .Cmd ("builder" , "prune" ).Run ()
171
171
imageName := testutil .Identifier (t )
172
172
defer base .Cmd ("rmi" , imageName ).Run ()
173
173
@@ -198,8 +198,8 @@ CMD ["echo", "nerdctl-build-test-dockerfile"]
198
198
199
199
func TestBuildLocal (t * testing.T ) {
200
200
testutil .RequiresBuild (t )
201
+ testutil .RegisterBuildCacheCleanup (t )
201
202
base := testutil .NewBase (t )
202
- defer base .Cmd ("builder" , "prune" ).Run ()
203
203
const testFileName = "nerdctl-build-test"
204
204
const testContent = "nerdctl"
205
205
outputDir := t .TempDir ()
@@ -243,8 +243,8 @@ func createBuildContext(t *testing.T, dockerfile string) string {
243
243
244
244
func TestBuildWithBuildArg (t * testing.T ) {
245
245
testutil .RequiresBuild (t )
246
+ testutil .RegisterBuildCacheCleanup (t )
246
247
base := testutil .NewBase (t )
247
- defer base .Cmd ("builder" , "prune" ).Run ()
248
248
imageName := testutil .Identifier (t )
249
249
defer base .Cmd ("rmi" , imageName ).Run ()
250
250
@@ -288,8 +288,8 @@ CMD echo $TEST_STRING
288
288
289
289
func TestBuildWithIIDFile (t * testing.T ) {
290
290
testutil .RequiresBuild (t )
291
+ testutil .RegisterBuildCacheCleanup (t )
291
292
base := testutil .NewBase (t )
292
- defer base .Cmd ("builder" , "prune" ).Run ()
293
293
imageName := testutil .Identifier (t )
294
294
defer base .Cmd ("rmi" , imageName ).Run ()
295
295
@@ -312,8 +312,8 @@ CMD ["echo", "nerdctl-build-test-string"]
312
312
313
313
func TestBuildWithLabels (t * testing.T ) {
314
314
testutil .RequiresBuild (t )
315
+ testutil .RegisterBuildCacheCleanup (t )
315
316
base := testutil .NewBase (t )
316
- defer base .Cmd ("builder" , "prune" ).Run ()
317
317
imageName := testutil .Identifier (t )
318
318
319
319
dockerfile := fmt .Sprintf (`FROM %s
@@ -330,8 +330,8 @@ LABEL name=nerdctl-build-test-label
330
330
331
331
func TestBuildMultipleTags (t * testing.T ) {
332
332
testutil .RequiresBuild (t )
333
+ testutil .RegisterBuildCacheCleanup (t )
333
334
base := testutil .NewBase (t )
334
- defer base .Cmd ("builder" , "prune" ).Run ()
335
335
img := testutil .Identifier (t )
336
336
imgWithNoTag , imgWithCustomTag := fmt .Sprintf ("%s%d" , img , 2 ), fmt .Sprintf ("%s%d:hello" , img , 3 )
337
337
defer base .Cmd ("rmi" , img ).AssertOK ()
@@ -354,10 +354,10 @@ func TestBuildMultipleTags(t *testing.T) {
354
354
}
355
355
356
356
func TestBuildWithContainerfile (t * testing.T ) {
357
- testutil .RequiresBuild (t )
358
357
testutil .DockerIncompatible (t )
358
+ testutil .RequiresBuild (t )
359
+ testutil .RegisterBuildCacheCleanup (t )
359
360
base := testutil .NewBase (t )
360
- defer base .Cmd ("builder" , "prune" ).Run ()
361
361
imageName := testutil .Identifier (t )
362
362
defer base .Cmd ("rmi" , imageName ).Run ()
363
363
@@ -375,8 +375,8 @@ CMD ["echo", "nerdctl-build-test-string"]
375
375
376
376
func TestBuildWithDockerFileAndContainerfile (t * testing.T ) {
377
377
testutil .RequiresBuild (t )
378
+ testutil .RegisterBuildCacheCleanup (t )
378
379
base := testutil .NewBase (t )
379
- defer base .Cmd ("builder" , "prune" ).Run ()
380
380
imageName := testutil .Identifier (t )
381
381
defer base .Cmd ("rmi" , imageName ).Run ()
382
382
@@ -404,8 +404,8 @@ CMD ["echo", "dockerfile"]
404
404
405
405
func TestBuildNoTag (t * testing.T ) {
406
406
testutil .RequiresBuild (t )
407
+ testutil .RegisterBuildCacheCleanup (t )
407
408
base := testutil .NewBase (t )
408
- defer base .Cmd ("builder" , "prune" ).AssertOK ()
409
409
base .Cmd ("image" , "prune" , "--force" , "--all" ).AssertOK ()
410
410
411
411
dockerfile := fmt .Sprintf (`FROM %s
@@ -420,8 +420,8 @@ CMD ["echo", "nerdctl-build-notag-string"]
420
420
421
421
func TestBuildContextDockerImageAlias (t * testing.T ) {
422
422
testutil .RequiresBuild (t )
423
+ testutil .RegisterBuildCacheCleanup (t )
423
424
base := testutil .NewBase (t )
424
- defer base .Cmd ("builder" , "prune" ).AssertOK ()
425
425
base .Cmd ("image" , "prune" , "--force" , "--all" ).AssertOK ()
426
426
427
427
dockerfile := `FROM myorg/myapp
@@ -435,8 +435,8 @@ CMD ["echo", "nerdctl-build-myorg/myapp"]`
435
435
436
436
func TestBuildContextWithCopyFromDir (t * testing.T ) {
437
437
testutil .RequiresBuild (t )
438
+ testutil .RegisterBuildCacheCleanup (t )
438
439
base := testutil .NewBase (t )
439
- defer base .Cmd ("builder" , "prune" ).AssertOK ()
440
440
base .Cmd ("image" , "prune" , "--force" , "--all" ).AssertOK ()
441
441
442
442
content := "hello_from_dir_2"
@@ -487,8 +487,8 @@ CMD ["cat", "/source-date-epoch"]
487
487
488
488
func TestBuildNetwork (t * testing.T ) {
489
489
testutil .RequiresBuild (t )
490
+ testutil .RegisterBuildCacheCleanup (t )
490
491
base := testutil .NewBase (t )
491
- defer base .Cmd ("builder" , "prune" ).AssertOK ()
492
492
493
493
dockerfile := fmt .Sprintf (`FROM %s
494
494
RUN apk add --no-cache curl
@@ -540,14 +540,14 @@ func buildWithNamedBuilder(base *testutil.Base, builderName string, args ...stri
540
540
541
541
func TestBuildAttestation (t * testing.T ) {
542
542
testutil .RequiresBuild (t )
543
+ testutil .RegisterBuildCacheCleanup (t )
543
544
base := testutil .NewBase (t )
544
545
builderName := testutil .Identifier (t )
545
546
if testutil .GetTarget () == testutil .Docker {
546
547
// create named builder for docker
547
548
defer base .Cmd ("buildx" , "rm" , builderName ).AssertOK ()
548
549
base .Cmd ("buildx" , "create" , "--name" , builderName , "--bootstrap" , "--use" ).AssertOK ()
549
550
}
550
- defer base .Cmd ("builder" , "prune" ).Run ()
551
551
552
552
dockerfile := "FROM " + testutil .NginxAlpineImage
553
553
buildCtx := createBuildContext (t , dockerfile )
0 commit comments