@@ -43,13 +43,15 @@ import (
43
43
44
44
const (
45
45
testContainerLabel = "envbox-integration-test"
46
+ testImageAlpine = "localhost:5000/envbuilder-test-alpine:latest"
47
+ testImageUbuntu = "localhost:5000/envbuilder-test-ubuntu:latest"
46
48
)
47
49
48
50
func TestFailsGitAuth (t * testing.T ) {
49
51
t .Parallel ()
50
52
url := createGitServer (t , gitServerOptions {
51
53
files : map [string ]string {
52
- "Dockerfile" : "FROM alpine:latest" ,
54
+ "Dockerfile" : "FROM " + testImageAlpine ,
53
55
},
54
56
username : "kyle" ,
55
57
password : "testing" ,
@@ -64,7 +66,7 @@ func TestSucceedsGitAuth(t *testing.T) {
64
66
t .Parallel ()
65
67
url := createGitServer (t , gitServerOptions {
66
68
files : map [string ]string {
67
- "Dockerfile" : "FROM alpine:latest" ,
69
+ "Dockerfile" : "FROM " + testImageAlpine ,
68
70
},
69
71
username : "kyle" ,
70
72
password : "testing" ,
@@ -142,7 +144,7 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
142
144
}
143
145
}
144
146
}` ,
145
- ".devcontainer/Dockerfile" : "FROM ubuntu" ,
147
+ ".devcontainer/Dockerfile" : "FROM " + testImageUbuntu ,
146
148
".devcontainer/feature3/devcontainer-feature.json" : string (feature3Spec ),
147
149
".devcontainer/feature3/install.sh" : "echo $GRAPE > /test3output" ,
148
150
},
@@ -166,7 +168,7 @@ func TestBuildFromDockerfile(t *testing.T) {
166
168
// Ensures that a Git repository with a Dockerfile is cloned and built.
167
169
url := createGitServer (t , gitServerOptions {
168
170
files : map [string ]string {
169
- "Dockerfile" : "FROM alpine:latest" ,
171
+ "Dockerfile" : "FROM " + testImageAlpine ,
170
172
},
171
173
})
172
174
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -183,7 +185,7 @@ func TestBuildPrintBuildOutput(t *testing.T) {
183
185
// Ensures that a Git repository with a Dockerfile is cloned and built.
184
186
url := createGitServer (t , gitServerOptions {
185
187
files : map [string ]string {
186
- "Dockerfile" : "FROM alpine:latest \n RUN echo hello" ,
188
+ "Dockerfile" : "FROM " + testImageAlpine + " \n RUN echo hello" ,
187
189
},
188
190
})
189
191
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -211,7 +213,7 @@ func TestBuildIgnoreVarRunSecrets(t *testing.T) {
211
213
// Ensures that a Git repository with a Dockerfile is cloned and built.
212
214
url := createGitServer (t , gitServerOptions {
213
215
files : map [string ]string {
214
- "Dockerfile" : "FROM alpine:latest" ,
216
+ "Dockerfile" : "FROM " + testImageAlpine ,
215
217
},
216
218
})
217
219
dir := t .TempDir ()
@@ -234,7 +236,7 @@ func TestBuildWithSetupScript(t *testing.T) {
234
236
// Ensures that a Git repository with a Dockerfile is cloned and built.
235
237
url := createGitServer (t , gitServerOptions {
236
238
files : map [string ]string {
237
- "Dockerfile" : "FROM alpine:latest" ,
239
+ "Dockerfile" : "FROM " + testImageAlpine ,
238
240
},
239
241
})
240
242
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -260,7 +262,7 @@ func TestBuildFromDevcontainerInCustomPath(t *testing.T) {
260
262
"dockerfile": "Dockerfile"
261
263
},
262
264
}` ,
263
- ".devcontainer/custom/Dockerfile" : "FROM ubuntu" ,
265
+ ".devcontainer/custom/Dockerfile" : "FROM " + testImageUbuntu ,
264
266
},
265
267
})
266
268
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -285,7 +287,7 @@ func TestBuildFromDevcontainerInSubfolder(t *testing.T) {
285
287
"dockerfile": "Dockerfile"
286
288
},
287
289
}` ,
288
- ".devcontainer/subfolder/Dockerfile" : "FROM ubuntu" ,
290
+ ".devcontainer/subfolder/Dockerfile" : "FROM " + testImageUbuntu ,
289
291
},
290
292
})
291
293
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -308,7 +310,7 @@ func TestBuildFromDevcontainerInRoot(t *testing.T) {
308
310
"dockerfile": "Dockerfile"
309
311
},
310
312
}` ,
311
- "Dockerfile" : "FROM ubuntu" ,
313
+ "Dockerfile" : "FROM " + testImageUbuntu ,
312
314
},
313
315
})
314
316
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -323,7 +325,7 @@ func TestBuildFromDevcontainerInRoot(t *testing.T) {
323
325
func TestBuildCustomCertificates (t * testing.T ) {
324
326
srv := httptest .NewTLSServer (createGitHandler (t , gitServerOptions {
325
327
files : map [string ]string {
326
- "Dockerfile" : "FROM alpine:latest" ,
328
+ "Dockerfile" : "FROM " + testImageAlpine ,
327
329
},
328
330
}))
329
331
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -344,7 +346,7 @@ func TestBuildStopStartCached(t *testing.T) {
344
346
// Ensures that a Git repository with a Dockerfile is cloned and built.
345
347
url := createGitServer (t , gitServerOptions {
346
348
files : map [string ]string {
347
- "Dockerfile" : "FROM alpine:latest" ,
349
+ "Dockerfile" : "FROM " + testImageAlpine ,
348
350
},
349
351
})
350
352
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -407,7 +409,7 @@ func TestBuildFailsFallback(t *testing.T) {
407
409
// Ensures that a Git repository with a Dockerfile is cloned and built.
408
410
url := createGitServer (t , gitServerOptions {
409
411
files : map [string ]string {
410
- "Dockerfile" : `FROM alpine
412
+ "Dockerfile" : `FROM ` + testImageAlpine + `
411
413
RUN exit 1` ,
412
414
},
413
415
})
@@ -439,7 +441,7 @@ RUN exit 1`,
439
441
})
440
442
ctr , err := runEnvbuilder (t , options {env : []string {
441
443
"GIT_URL=" + url ,
442
- "FALLBACK_IMAGE=alpine:latest" ,
444
+ "FALLBACK_IMAGE=" + testImageAlpine ,
443
445
}})
444
446
require .NoError (t , err )
445
447
@@ -458,7 +460,7 @@ func TestExitBuildOnFailure(t *testing.T) {
458
460
_ , err := runEnvbuilder (t , options {env : []string {
459
461
"GIT_URL=" + url ,
460
462
"DOCKERFILE_PATH=Dockerfile" ,
461
- "FALLBACK_IMAGE=alpine" ,
463
+ "FALLBACK_IMAGE=" + testImageAlpine ,
462
464
// Ensures that the fallback doesn't work when an image is specified.
463
465
"EXIT_ON_BUILD_FAILURE=true" ,
464
466
}})
@@ -486,7 +488,7 @@ func TestContainerEnv(t *testing.T) {
486
488
"REMOTE_BAR": "${FROM_CONTAINER_ENV}"
487
489
}
488
490
}` ,
489
- ".devcontainer/Dockerfile" : "FROM alpine:latest \n ENV FROM_DOCKERFILE=foo" ,
491
+ ".devcontainer/Dockerfile" : "FROM " + testImageAlpine + " \n ENV FROM_DOCKERFILE=foo" ,
490
492
},
491
493
})
492
494
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -523,7 +525,7 @@ func TestLifecycleScripts(t *testing.T) {
523
525
"parallel2": ["sh", "-c", "echo parallel2 > /tmp/parallel2"]
524
526
}
525
527
}` ,
526
- ".devcontainer/Dockerfile" : "FROM alpine:latest \n USER nobody" ,
528
+ ".devcontainer/Dockerfile" : "FROM " + testImageAlpine + " \n USER nobody" ,
527
529
},
528
530
})
529
531
ctr , err := runEnvbuilder (t , options {env : []string {
@@ -559,7 +561,7 @@ func TestPostStartScript(t *testing.T) {
559
561
".devcontainer/init.sh" : `#!/bin/sh
560
562
/tmp/post-start.sh
561
563
sleep infinity` ,
562
- ".devcontainer/Dockerfile" : `FROM alpine:latest
564
+ ".devcontainer/Dockerfile" : `FROM ` + testImageAlpine + `
563
565
COPY init.sh /bin
564
566
RUN chmod +x /bin/init.sh
565
567
USER nobody` ,
@@ -586,7 +588,9 @@ func TestPrivateRegistry(t *testing.T) {
586
588
t .Parallel ()
587
589
t .Run ("NoAuth" , func (t * testing.T ) {
588
590
t .Parallel ()
589
- image := setupPassthroughRegistry (t , "library/alpine" , & registryAuth {
591
+ // Even if something goes wrong with auth,
592
+ // the pull will fail as "scratch" is a reserved name.
593
+ image := setupPassthroughRegistry (t , "scratch" , & registryAuth {
590
594
Username : "user" ,
591
595
Password : "test" ,
592
596
})
@@ -605,7 +609,7 @@ func TestPrivateRegistry(t *testing.T) {
605
609
})
606
610
t .Run ("Auth" , func (t * testing.T ) {
607
611
t .Parallel ()
608
- image := setupPassthroughRegistry (t , "library/ alpine" , & registryAuth {
612
+ image := setupPassthroughRegistry (t , "envbuilder-test- alpine:latest " , & registryAuth {
609
613
Username : "user" ,
610
614
Password : "test" ,
611
615
})
@@ -635,7 +639,9 @@ func TestPrivateRegistry(t *testing.T) {
635
639
})
636
640
t .Run ("InvalidAuth" , func (t * testing.T ) {
637
641
t .Parallel ()
638
- image := setupPassthroughRegistry (t , "library/alpine" , & registryAuth {
642
+ // Even if something goes wrong with auth,
643
+ // the pull will fail as "scratch" is a reserved name.
644
+ image := setupPassthroughRegistry (t , "scratch" , & registryAuth {
639
645
Username : "user" ,
640
646
Password : "banana" ,
641
647
})
@@ -672,22 +678,22 @@ type registryAuth struct {
672
678
673
679
func setupPassthroughRegistry (t * testing.T , image string , auth * registryAuth ) string {
674
680
t .Helper ()
675
- dockerURL , err := url .Parse ("https ://registry-1.docker.io " )
681
+ dockerURL , err := url .Parse ("http ://localhost:5000 " )
676
682
require .NoError (t , err )
677
683
proxy := httputil .NewSingleHostReverseProxy (dockerURL )
678
684
679
685
// The Docker registry uses short-lived JWTs to authenticate
680
686
// anonymously to pull images. To test our MITM auth, we need to
681
687
// generate a JWT for the proxy to use.
682
- registry , err := name .NewRegistry ("registry-1.docker.io " )
688
+ registry , err := name .NewRegistry ("localhost:5000 " )
683
689
require .NoError (t , err )
684
690
proxy .Transport , err = transport .NewWithContext (context .Background (), registry , authn .Anonymous , http .DefaultTransport , []string {})
685
691
require .NoError (t , err )
686
692
687
693
srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
688
- r .Host = "registry-1.docker.io "
689
- r .URL .Host = "registry-1.docker.io "
690
- r .URL .Scheme = "https "
694
+ r .Host = "localhost:5000 "
695
+ r .URL .Host = "localhost:5000 "
696
+ r .URL .Scheme = "http "
691
697
692
698
if auth != nil {
693
699
user , pass , ok := r .BasicAuth ()
0 commit comments