@@ -30,6 +30,7 @@ import (
3030 "github.com/docker/docker/api/types"
3131 "github.com/docker/docker/api/types/container"
3232 "github.com/docker/docker/api/types/filters"
33+ "github.com/docker/docker/api/types/image"
3334 "github.com/docker/docker/api/types/mount"
3435 "github.com/docker/docker/api/types/volume"
3536 "github.com/docker/docker/client"
@@ -1396,6 +1397,74 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine),
13961397 })
13971398}
13981399
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+
13991468func TestChownHomedir (t * testing.T ) {
14001469 t .Parallel ()
14011470
0 commit comments