11import { buildImage } from "./build" ;
22import {
33 getCloudflareContainerRegistry ,
4+ getDevContainerImageName ,
45 isCloudflareRegistryLink ,
56} from "./knobs" ;
67import { dockerLoginManagedRegistry } from "./login" ;
7- import { ContainerDevOptions } from "./types" ;
8+ import { ContainerNormalisedConfig , RegistryLinkConfig } from "./types" ;
89import {
910 checkExposedPorts ,
10- isDockerfile ,
1111 runDockerCmd ,
1212 verifyDockerInstalled ,
1313} from "./utils" ;
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,14 +52,14 @@ export async function pullImage(
5152 */
5253export async function prepareContainerImagesForDev (
5354 dockerPath : string ,
54- containerOptions : ContainerDevOptions [ ] ,
55- configPath : string | undefined ,
55+ containerOptions : ContainerNormalisedConfig [ ] ,
56+ containerBuildId : string ,
5657 onContainerImagePreparationStart : ( args : {
57- containerOptions : ContainerDevOptions ;
58+ containerOptions : ContainerNormalisedConfig ;
5859 abort : ( ) => void ;
5960 } ) => void ,
6061 onContainerImagePreparationEnd : ( args : {
61- containerOptions : ContainerDevOptions ;
62+ containerOptions : ContainerNormalisedConfig ;
6263 } ) => void
6364) {
6465 let aborted = false ;
@@ -69,8 +70,9 @@ export async function prepareContainerImagesForDev(
6970 }
7071 await verifyDockerInstalled ( dockerPath ) ;
7172 for ( const options of containerOptions ) {
72- if ( isDockerfile ( options . image , configPath ) ) {
73- const build = await buildImage ( dockerPath , options , configPath ) ;
73+ const tag = getDevContainerImageName ( options . class_name , containerBuildId ) ;
74+ if ( "dockerfile" in options ) {
75+ const build = await buildImage ( dockerPath , options , tag ) ;
7476 onContainerImagePreparationStart ( {
7577 containerOptions : options ,
7678 abort : ( ) => {
@@ -83,13 +85,13 @@ export async function prepareContainerImagesForDev(
8385 containerOptions : options ,
8486 } ) ;
8587 } else {
86- if ( ! isCloudflareRegistryLink ( options . image ) ) {
88+ if ( ! isCloudflareRegistryLink ( options . registry_link ) ) {
8789 throw new Error (
88- `Image "${ options . image } " is a registry link but does not point to the Cloudflare container registry.\n` +
90+ `Image "${ options . registry_link } " is a registry link but does not point to the Cloudflare container registry.\n` +
8991 `To use an existing image from another repository, see https://developers.cloudflare.com/containers/image-management/#using-existing-images`
9092 ) ;
9193 }
92- const pull = await pullImage ( dockerPath , options ) ;
94+ const pull = await pullImage ( dockerPath , options , tag ) ;
9395 onContainerImagePreparationStart ( {
9496 containerOptions : options ,
9597 abort : ( ) => {
@@ -103,7 +105,7 @@ export async function prepareContainerImagesForDev(
103105 } ) ;
104106 }
105107 if ( ! aborted ) {
106- await checkExposedPorts ( dockerPath , options ) ;
108+ await checkExposedPorts ( dockerPath , options , tag ) ;
107109 }
108110 }
109111}
0 commit comments