File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
wrangler/src/__tests__/containers Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/containers-shared " : patch
3+ ---
4+
5+ Correctly handle image names that contain a slash
Original file line number Diff line number Diff line change @@ -132,21 +132,31 @@ export async function prepareContainerImagesForDev(args: {
132132 * anyother-registry.com/anything -> no change
133133 */
134134export function resolveImageName ( accountId : string , image : string ) : string {
135- let url : URL ;
135+ let url : URL | undefined ;
136136 try {
137137 url = new URL ( `http://${ image } ` ) ;
138138 } catch {
139- // not a valid url so assume it is in the format image:tag and pre-pend the registry
139+ // Invalid URL
140+ }
141+
142+ if (
143+ url === undefined ||
144+ ( ! url . host . match ( / [: .] / ) && url . hostname !== "localhost" )
145+ ) {
146+ // Not a valid URL so assume it is in the format image:tag and prepend the registry
140147 return getCloudflareRegistryWithAccountNamespace ( accountId , image ) ;
141148 }
142- // hostname not the managed registry, passthrough
149+
143150 if ( url . hostname !== getCloudflareContainerRegistry ( ) ) {
151+ // hostname not the managed registry, passthrough
144152 return image ;
145153 }
146- // is managed registry and has the account id, passthrough
154+
147155 if ( url . pathname . startsWith ( `/${ accountId } ` ) ) {
156+ // is managed registry and has the account id, passthrough
148157 return image ;
149158 }
159+
150160 // check if already looks like it has an account id (32 char hex string)
151161 const accountIdPattern = / ^ \/ ( [ a - f 0 - 9 ] { 32 } ) \/ / ;
152162 const match = accountIdPattern . exec ( url . pathname ) ;
Original file line number Diff line number Diff line change @@ -100,6 +100,21 @@ describe("containers push", () => {
100100 ] ) ;
101101 } ) ;
102102
103+ it ( "should tag image with the correct uri if given an <namespace>/<image>:<tag> argument" , async ( ) => {
104+ await runWrangler ( "containers push test-namespace/app:tag" ) ;
105+
106+ expect ( runDockerCmd ) . toHaveBeenCalledTimes ( 2 ) ;
107+ expect ( runDockerCmd ) . toHaveBeenNthCalledWith ( 1 , "docker" , [
108+ "tag" ,
109+ `test-namespace/app:tag` ,
110+ `${ getCloudflareContainerRegistry ( ) } /some-account-id/test-namespace/app:tag` ,
111+ ] ) ;
112+ expect ( runDockerCmd ) . toHaveBeenNthCalledWith ( 2 , "docker" , [
113+ "push" ,
114+ `${ getCloudflareContainerRegistry ( ) } /some-account-id/test-namespace/app:tag` ,
115+ ] ) ;
116+ } ) ;
117+
103118 it ( "should tag image with the correct uri if given an registry.cloudflare.com/<image>:<tag> argument" , async ( ) => {
104119 setIsTTY ( false ) ;
105120 setWranglerConfig ( { } ) ;
You can’t perform that action at this time.
0 commit comments