11import { buildImage } from "./build" ;
22import {
33 getCloudflareContainerRegistry ,
4+ getDevContainerImageName ,
45 isCloudflareRegistryLink ,
56} from "./knobs" ;
67import { dockerLoginManagedRegistry } from "./login" ;
7- import { type ContainerDevOptions } from "./types" ;
88import {
99 checkExposedPorts ,
10- isDockerfile ,
1110 runDockerCmd ,
1211 verifyDockerInstalled ,
1312} from "./utils" ;
13+ import type { ContainerNormalisedConfig , RegistryLinkConfig } from "./types" ;
1414
1515export async function pullImage (
1616 dockerPath : string ,
17- options : ContainerDevOptions
17+ options : RegistryLinkConfig ,
18+ tag : string
1819) : Promise < { abort : ( ) => void ; ready : Promise < void > } > {
1920 await dockerLoginManagedRegistry ( dockerPath ) ;
2021 const pull = runDockerCmd ( dockerPath , [
2122 "pull" ,
22- options . image ,
23+ options . registry_link ,
2324 // All containers running on our platform need to be built for amd64 architecture, but by default docker pull seems to look for an image matching the host system, so we need to specify this here
2425 "--platform" ,
2526 "linux/amd64" ,
2627 ] ) ;
2728 const ready = pull . ready . then ( async ( { aborted } : { aborted : boolean } ) => {
2829 if ( ! aborted ) {
2930 // re-tag image with the expected dev-formatted image tag for consistency
30- await runDockerCmd ( dockerPath , [ "tag" , options . image , options . imageTag ] ) ;
31+ await runDockerCmd ( dockerPath , [ "tag" , options . registry_link , tag ] ) ;
3132 }
3233 } ) ;
3334
@@ -51,19 +52,17 @@ export async function pullImage(
5152 */
5253export async function prepareContainerImagesForDev ( options : {
5354 dockerPath : string ;
54- configPath ?: string ;
55- containerOptions : ContainerDevOptions [ ] ;
55+ containerOptions : ContainerNormalisedConfig [ ] ;
5656 onContainerImagePreparationStart : ( args : {
57- containerOptions : ContainerDevOptions ;
57+ containerOptions : ContainerNormalisedConfig ;
5858 abort : ( ) => void ;
5959 } ) => void ;
6060 onContainerImagePreparationEnd : ( args : {
61- containerOptions : ContainerDevOptions ;
61+ containerOptions : ContainerNormalisedConfig [ ] ;
6262 } ) => void ;
6363} ) {
6464 const {
6565 dockerPath,
66- configPath,
6766 containerOptions,
6867 onContainerImagePreparationStart,
6968 onContainerImagePreparationEnd,
@@ -76,8 +75,9 @@ export async function prepareContainerImagesForDev(options: {
7675 }
7776 await verifyDockerInstalled ( dockerPath ) ;
7877 for ( const options of containerOptions ) {
79- if ( isDockerfile ( options . image , configPath ) ) {
80- const build = await buildImage ( dockerPath , options , configPath ) ;
78+ const tag = getDevContainerImageName ( options . class_name , containerBuildId ) ;
79+ if ( "dockerfile" in options ) {
80+ const build = await buildImage ( dockerPath , options , tag ) ;
8181 onContainerImagePreparationStart ( {
8282 containerOptions : options ,
8383 abort : ( ) => {
@@ -90,13 +90,13 @@ export async function prepareContainerImagesForDev(options: {
9090 containerOptions : options ,
9191 } ) ;
9292 } else {
93- if ( ! isCloudflareRegistryLink ( options . image ) ) {
93+ if ( ! isCloudflareRegistryLink ( options . registry_link ) ) {
9494 throw new Error (
95- `Image "${ options . image } " is a registry link but does not point to the Cloudflare container registry.\n` +
95+ `Image "${ options . registry_link } " is a registry link but does not point to the Cloudflare container registry.\n` +
9696 `To use an existing image from another repository, see https://developers.cloudflare.com/containers/image-management/#using-existing-images`
9797 ) ;
9898 }
99- const pull = await pullImage ( dockerPath , options ) ;
99+ const pull = await pullImage ( dockerPath , options , tag ) ;
100100 onContainerImagePreparationStart ( {
101101 containerOptions : options ,
102102 abort : ( ) => {
@@ -110,7 +110,7 @@ export async function prepareContainerImagesForDev(options: {
110110 } ) ;
111111 }
112112 if ( ! aborted ) {
113- await checkExposedPorts ( dockerPath , options ) ;
113+ await checkExposedPorts ( dockerPath , options , tag ) ;
114114 }
115115 }
116116}
0 commit comments