@@ -119,6 +119,50 @@ describe("buildAndMaybePush", () => {
119119 expect ( dockerLoginManagedRegistry ) . toHaveBeenCalledOnce ( ) ;
120120 } ) ;
121121
122+ it ( "should be able to build image and not push if it already exists in remote" , async ( ) => {
123+ vi . mocked ( getDockerImageDigest ) . mockResolvedValue ( "three" ) ;
124+ vi . mocked ( runDockerCmd ) . mockResolvedValueOnce ( ) ;
125+ await runWrangler (
126+ "containers build ./container-context -t test-app:tag -p"
127+ ) ;
128+ expect ( dockerBuild ) . toHaveBeenCalledWith ( "docker" , {
129+ buildCmd : [
130+ "build" ,
131+ "-t" ,
132+ `${ getCloudflareContainerRegistry ( ) } /test_account_id/test-app:tag` ,
133+ "--platform" ,
134+ "linux/amd64" ,
135+ "--provenance=false" ,
136+ "-f" ,
137+ "-" ,
138+ "./container-context" ,
139+ ] ,
140+ dockerfile,
141+ } ) ;
142+ expect ( runDockerCmd ) . toHaveBeenCalledTimes ( 2 ) ;
143+ expect ( runDockerCmd ) . toHaveBeenNthCalledWith (
144+ 1 ,
145+ "docker" ,
146+ [
147+ "manifest" ,
148+ "inspect" ,
149+ `${ getCloudflareContainerRegistry ( ) } /test_account_id/test-app@three` ,
150+ ] ,
151+ "ignore"
152+ ) ;
153+ expect ( runDockerCmd ) . toHaveBeenNthCalledWith ( 2 , "docker" , [
154+ "image" ,
155+ "rm" ,
156+ `${ getCloudflareContainerRegistry ( ) } /test_account_id/test-app:tag` ,
157+ ] ) ;
158+ expect ( dockerImageInspect ) . toHaveBeenCalledOnce ( ) ;
159+ expect ( dockerImageInspect ) . toHaveBeenCalledWith ( "docker" , {
160+ imageTag : `${ getCloudflareContainerRegistry ( ) } /test_account_id/test-app:tag` ,
161+ formatString : "{{ .Size }} {{ len .RootFS.Layers }}" ,
162+ } ) ;
163+ expect ( dockerLoginManagedRegistry ) . toHaveBeenCalledOnce ( ) ;
164+ } ) ;
165+
122166 it ( "should be able to build image and not push" , async ( ) => {
123167 await runWrangler ( "containers build ./container-context -t test-app" ) ;
124168 expect ( dockerBuild ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments