@@ -1138,16 +1138,63 @@ func TestPushImage(t *testing.T) {
1138
1138
require .NoError (t , err )
1139
1139
1140
1140
// Then: the image should be pushed
1141
- _ , err = remote .Image (ref )
1141
+ img , err : = remote .Image (ref )
1142
1142
require .NoError (t , err , "expected image to be present after build + push" )
1143
1143
1144
+ // Then: the image should have its directives replaced with those required
1145
+ // to run envbuilder automatically
1146
+ configFile , err := img .ConfigFile ()
1147
+ require .NoError (t , err , "expected image to return a config file" )
1148
+
1149
+ assert .Equal (t , "root" , configFile .Config .User , "user must be root" )
1150
+ assert .Equal (t , "/" , configFile .Config .WorkingDir , "workdir must be /" )
1151
+ if assert .Len (t , configFile .Config .Entrypoint , 1 ) {
1152
+ assert .Equal (t , "/.envbuilder/bin/envbuilder" , configFile .Config .Entrypoint [0 ], "incorrect entrypoint" )
1153
+ }
1154
+
1144
1155
// Then: re-running envbuilder with GET_CACHED_IMAGE should succeed
1145
1156
_ , err = runEnvbuilder (t , options {env : []string {
1146
1157
envbuilderEnv ("GIT_URL" , srv .URL ),
1147
1158
envbuilderEnv ("CACHE_REPO" , testRepo ),
1148
1159
envbuilderEnv ("GET_CACHED_IMAGE" , "1" ),
1149
1160
}})
1150
1161
require .NoError (t , err )
1162
+
1163
+ // When: we pull the image we just built
1164
+ ctx , cancel := context .WithCancel (context .Background ())
1165
+ t .Cleanup (cancel )
1166
+ cli , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
1167
+ require .NoError (t , err )
1168
+ defer cli .Close ()
1169
+ rc , err := cli .ImagePull (ctx , ref .String (), image.PullOptions {})
1170
+ require .NoError (t , err )
1171
+ t .Cleanup (func () { _ = rc .Close () })
1172
+ _ , err = io .ReadAll (rc )
1173
+ require .NoError (t , err )
1174
+
1175
+ // When: we run the image we just built
1176
+ ctr , err := cli .ContainerCreate (ctx , & container.Config {
1177
+ Image : ref .String (),
1178
+ Entrypoint : []string {"sleep" , "infinity" },
1179
+ Labels : map [string ]string {
1180
+ testContainerLabel : "true" ,
1181
+ },
1182
+ }, nil , nil , nil , "" )
1183
+ require .NoError (t , err )
1184
+ t .Cleanup (func () {
1185
+ _ = cli .ContainerRemove (ctx , ctr .ID , container.RemoveOptions {
1186
+ RemoveVolumes : true ,
1187
+ Force : true ,
1188
+ })
1189
+ })
1190
+ err = cli .ContainerStart (ctx , ctr .ID , container.StartOptions {})
1191
+ require .NoError (t , err )
1192
+
1193
+ // Then: the envbuilder binary exists in the image!
1194
+ out := execContainer (t , ctr .ID , "/.envbuilder/bin/envbuilder --help" )
1195
+ require .Regexp (t , `(?s)^USAGE:\s+envbuilder` , strings .TrimSpace (out ))
1196
+ out = execContainer (t , ctr .ID , "cat /root/date.txt" )
1197
+ require .NotEmpty (t , strings .TrimSpace (out ))
1151
1198
})
1152
1199
1153
1200
t .Run ("CacheAndPushAuth" , func (t * testing.T ) {
@@ -1397,74 +1444,6 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine),
1397
1444
})
1398
1445
}
1399
1446
1400
- func TestEmbedBinaryImage (t * testing.T ) {
1401
- t .Parallel ()
1402
-
1403
- srv := createGitServer (t , gitServerOptions {
1404
- files : map [string ]string {
1405
- ".devcontainer/Dockerfile" : fmt .Sprintf ("FROM %s\n RUN date --utc > /root/date.txt" , testImageAlpine ),
1406
- ".devcontainer/devcontainer.json" : `{
1407
- "name": "Test",
1408
- "build": {
1409
- "dockerfile": "Dockerfile"
1410
- },
1411
- }` ,
1412
- },
1413
- })
1414
-
1415
- testReg := setupInMemoryRegistry (t , setupInMemoryRegistryOpts {})
1416
- testRepo := testReg + "/test-embed-binary-image"
1417
- ref , err := name .ParseReference (testRepo + ":latest" )
1418
- require .NoError (t , err )
1419
-
1420
- _ , err = runEnvbuilder (t , options {env : []string {
1421
- envbuilderEnv ("GIT_URL" , srv .URL ),
1422
- envbuilderEnv ("CACHE_REPO" , testRepo ),
1423
- envbuilderEnv ("PUSH_IMAGE" , "1" ),
1424
- }})
1425
- require .NoError (t , err )
1426
-
1427
- _ , err = remote .Image (ref )
1428
- require .NoError (t , err , "expected image to be present after build + push" )
1429
-
1430
- ctx := context .Background ()
1431
- cli , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
1432
- require .NoError (t , err )
1433
- t .Cleanup (func () {
1434
- cli .Close ()
1435
- })
1436
-
1437
- // Pull the image we just built
1438
- rc , err := cli .ImagePull (ctx , ref .String (), image.PullOptions {})
1439
- require .NoError (t , err )
1440
- t .Cleanup (func () { _ = rc .Close () })
1441
- _ , err = io .ReadAll (rc )
1442
- require .NoError (t , err )
1443
-
1444
- // Run it
1445
- ctr , err := cli .ContainerCreate (ctx , & container.Config {
1446
- Image : ref .String (),
1447
- Cmd : []string {"sleep" , "infinity" },
1448
- Labels : map [string ]string {
1449
- testContainerLabel : "true" ,
1450
- },
1451
- }, nil , nil , nil , "" )
1452
- require .NoError (t , err )
1453
- t .Cleanup (func () {
1454
- _ = cli .ContainerRemove (ctx , ctr .ID , container.RemoveOptions {
1455
- RemoveVolumes : true ,
1456
- Force : true ,
1457
- })
1458
- })
1459
- err = cli .ContainerStart (ctx , ctr .ID , container.StartOptions {})
1460
- require .NoError (t , err )
1461
-
1462
- out := execContainer (t , ctr .ID , "[[ -f \" /.envbuilder/bin/envbuilder\" ]] && echo \" exists\" " )
1463
- require .Equal (t , "exists" , strings .TrimSpace (out ))
1464
- out = execContainer (t , ctr .ID , "cat /root/date.txt" )
1465
- require .NotEmpty (t , strings .TrimSpace (out ))
1466
- }
1467
-
1468
1447
func TestChownHomedir (t * testing.T ) {
1469
1448
t .Parallel ()
1470
1449
0 commit comments