@@ -20,86 +20,97 @@ describe("GenericContainer Dockerfile", () => {
2020 const uuidGen = new RandomUuid ( ) ;
2121 const fixtures = path . resolve ( __dirname , ".." , ".." , "fixtures" , "docker" ) ;
2222
23- it ( "should build and start" , async ( ) => {
24- const context = path . resolve ( fixtures , "docker" ) ;
25- const container = await GenericContainer . fromDockerfile ( context ) . build ( ) ;
26- const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
23+ describe . each ( [ false , true ] ) ( "with buildKit=%s" , ( useBuildKit ) => {
24+ it ( "should build and start" , async ( ) => {
25+ const context = path . resolve ( fixtures , "docker" ) ;
26+ const container = await GenericContainer . fromDockerfile ( context ) . withBuildKit ( useBuildKit ) . build ( ) ;
27+ const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
2728
28- await checkContainerIsHealthy ( startedContainer ) ;
29+ await checkContainerIsHealthy ( startedContainer ) ;
2930
30- await startedContainer . stop ( ) ;
31- } ) ;
32-
33- it ( "should have a session ID label to be cleaned up by the Reaper" , async ( ) => {
34- const context = path . resolve ( fixtures , "docker" ) ;
35- const imageName = `${ uuidGen . nextUuid ( ) } :${ uuidGen . nextUuid ( ) } ` ;
36-
37- await GenericContainer . fromDockerfile ( context ) . build ( imageName ) ;
38-
39- const client = await getContainerRuntimeClient ( ) ;
40- const reaper = await getReaper ( client ) ;
41- const imageLabels = await getImageLabelsByName ( imageName ) ;
42- expect ( imageLabels [ LABEL_TESTCONTAINERS_SESSION_ID ] ) . toEqual ( reaper . sessionId ) ;
31+ await startedContainer . stop ( ) ;
32+ } ) ;
4333
44- await deleteImageByName ( imageName ) ;
45- } ) ;
34+ it ( "should have a session ID label to be cleaned up by the Reaper" , async ( ) => {
35+ const context = path . resolve ( fixtures , "docker" ) ;
36+ const imageName = `${ uuidGen . nextUuid ( ) } :${ uuidGen . nextUuid ( ) } ` ;
4637
47- it ( "should not have a session ID label when delete on exit set to false" , async ( ) => {
48- const context = path . resolve ( fixtures , "docker" ) ;
49- const imageName = `${ uuidGen . nextUuid ( ) } :${ uuidGen . nextUuid ( ) } ` ;
38+ await GenericContainer . fromDockerfile ( context ) . withBuildKit ( useBuildKit ) . build ( imageName ) ;
5039
51- await GenericContainer . fromDockerfile ( context ) . build ( imageName , { deleteOnExit : false } ) ;
40+ const client = await getContainerRuntimeClient ( ) ;
41+ const reaper = await getReaper ( client ) ;
42+ const imageLabels = await getImageLabelsByName ( imageName ) ;
43+ expect ( imageLabels [ LABEL_TESTCONTAINERS_SESSION_ID ] ) . toEqual ( reaper . sessionId ) ;
5244
53- const imageLabels = await getImageLabelsByName ( imageName ) ;
54- expect ( imageLabels [ LABEL_TESTCONTAINERS_SESSION_ID ] ) . toBeUndefined ( ) ;
45+ await deleteImageByName ( imageName ) ;
46+ } ) ;
5547
56- await deleteImageByName ( imageName ) ;
57- } ) ;
48+ it ( "should not have a session ID label when delete on exit set to false" , async ( ) => {
49+ const context = path . resolve ( fixtures , "docker" ) ;
50+ const imageName = `${ uuidGen . nextUuid ( ) } :${ uuidGen . nextUuid ( ) } ` ;
5851
59- // https://github.com/containers/podman/issues/17779
60- if ( ! process . env . CI_PODMAN ) {
61- it ( "should use pull policy" , async ( ) => {
62- const dockerfile = path . resolve ( fixtures , "docker" ) ;
63- const containerSpec = GenericContainer . fromDockerfile ( dockerfile ) . withPullPolicy ( PullPolicy . alwaysPull ( ) ) ;
52+ await GenericContainer . fromDockerfile ( context )
53+ . withBuildKit ( useBuildKit )
54+ . build ( imageName , { deleteOnExit : false } ) ;
6455
65- await containerSpec . build ( ) ;
66- const dockerEventStream = await getDockerEventStream ( ) ;
67- const dockerPullEventPromise = waitForDockerEvent ( dockerEventStream , "pull" ) ;
68- await containerSpec . build ( ) ;
69- await dockerPullEventPromise ;
56+ const imageLabels = await getImageLabelsByName ( imageName ) ;
57+ expect ( imageLabels [ LABEL_TESTCONTAINERS_SESSION_ID ] ) . toBeUndefined ( ) ;
7058
71- dockerEventStream . destroy ( ) ;
59+ await deleteImageByName ( imageName ) ;
7260 } ) ;
73- }
7461
75- it ( "should build and start with custom file name" , async ( ) => {
76- const context = path . resolve ( fixtures , "docker-with-custom-filename" ) ;
77- const container = await GenericContainer . fromDockerfile ( context , "Dockerfile-A" ) . build ( ) ;
78- const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
79-
80- await checkContainerIsHealthy ( startedContainer ) ;
81-
82- await startedContainer . stop ( ) ;
83- } ) ;
62+ // https://github.com/containers/podman/issues/17779
63+ if ( ! process . env . CI_PODMAN && ! useBuildKit ) {
64+ it ( "should use pull policy" , async ( ) => {
65+ const dockerfile = path . resolve ( fixtures , "docker" ) ;
66+ const containerSpec = GenericContainer . fromDockerfile ( dockerfile )
67+ . withBuildKit ( useBuildKit )
68+ . withPullPolicy ( PullPolicy . alwaysPull ( ) ) ;
69+
70+ await containerSpec . build ( ) ;
71+ const dockerEventStream = await getDockerEventStream ( ) ;
72+ const dockerPullEventPromise = waitForDockerEvent ( dockerEventStream , "pull" ) ;
73+ await containerSpec . build ( ) ;
74+ await dockerPullEventPromise ;
75+
76+ dockerEventStream . destroy ( ) ;
77+ } ) ;
78+ }
79+
80+ it ( "should build and start with custom file name" , async ( ) => {
81+ const context = path . resolve ( fixtures , "docker-with-custom-filename" ) ;
82+ const container = await GenericContainer . fromDockerfile ( context , "Dockerfile-A" )
83+ . withBuildKit ( useBuildKit )
84+ . build ( ) ;
85+ const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
86+
87+ await checkContainerIsHealthy ( startedContainer ) ;
88+
89+ await startedContainer . stop ( ) ;
90+ } ) ;
8491
85- it ( "should set build arguments" , async ( ) => {
86- const context = path . resolve ( fixtures , "docker-with-buildargs" ) ;
87- const container = await GenericContainer . fromDockerfile ( context ) . withBuildArgs ( { VERSION : "10-alpine" } ) . build ( ) ;
88- const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
92+ it ( "should set build arguments" , async ( ) => {
93+ const context = path . resolve ( fixtures , "docker-with-buildargs" ) ;
94+ const container = await GenericContainer . fromDockerfile ( context )
95+ . withBuildKit ( useBuildKit )
96+ . withBuildArgs ( { VERSION : "10-alpine" } )
97+ . build ( ) ;
98+ const startedContainer = await container . withExposedPorts ( 8080 ) . start ( ) ;
8999
90- await checkContainerIsHealthy ( startedContainer ) ;
100+ await checkContainerIsHealthy ( startedContainer ) ;
91101
92- await startedContainer . stop ( ) ;
93- } ) ;
102+ await startedContainer . stop ( ) ;
103+ } ) ;
94104
95- it ( "should exit immediately and stop without exception" , async ( ) => {
96- const message = "This container will exit immediately." ;
97- const context = path . resolve ( fixtures , "docker-exit-immediately" ) ;
98- const container = await GenericContainer . fromDockerfile ( context ) . build ( ) ;
99- const startedContainer = await container . withWaitStrategy ( Wait . forLogMessage ( message ) ) . start ( ) ;
105+ it ( "should exit immediately and stop without exception" , async ( ) => {
106+ const message = "This container will exit immediately." ;
107+ const context = path . resolve ( fixtures , "docker-exit-immediately" ) ;
108+ const container = await GenericContainer . fromDockerfile ( context ) . withBuildKit ( useBuildKit ) . build ( ) ;
109+ const startedContainer = await container . withWaitStrategy ( Wait . forLogMessage ( message ) ) . start ( ) ;
100110
101- await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
111+ await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
102112
103- await startedContainer . stop ( ) ;
113+ await startedContainer . stop ( ) ;
114+ } ) ;
104115 } ) ;
105116} ) ;
0 commit comments