@@ -8,16 +8,17 @@ import { safeReadJSONFile } from "../utilities/fileSystem.js";
88import { readFileSync } from "fs" ;
99import { isLinux } from "std-env" ;
1010import { z } from "zod" ;
11+ import { assertExhaustive } from "../utilities/assertExhaustive.js" ;
1112
1213export interface BuildImageOptions {
1314 // Common options
1415 isLocalBuild : boolean ;
1516 imagePlatform : string ;
1617 noCache ?: boolean ;
17- loadImage ?: boolean ;
18+ load ?: boolean ;
1819
1920 // Local build options
20- push : boolean ;
21+ push ? : boolean ;
2122 network ?: string ;
2223 builder : string ;
2324
@@ -50,7 +51,7 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
5051 imagePlatform,
5152 noCache,
5253 push,
53- loadImage ,
54+ load ,
5455 authAccessToken,
5556 imageTag,
5657 deploymentId,
@@ -83,7 +84,7 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
8384 contentHash,
8485 projectRef,
8586 push,
86- loadImage ,
87+ load ,
8788 noCache,
8889 extraCACerts,
8990 apiUrl,
@@ -113,7 +114,7 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
113114 deploymentVersion,
114115 contentHash,
115116 projectRef,
116- loadImage ,
117+ load ,
117118 imagePlatform,
118119 noCache,
119120 extraCACerts,
@@ -140,7 +141,7 @@ export interface DepotBuildImageOptions {
140141 apiUrl : string ;
141142 apiKey : string ;
142143 branchName ?: string ;
143- loadImage ?: boolean ;
144+ load ?: boolean ;
144145 noCache ?: boolean ;
145146 extraCACerts ?: string ;
146147 buildEnvVars ?: Record < string , string | undefined > ;
@@ -174,6 +175,7 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise<BuildI
174175 options . noCache ? "--no-cache" : undefined ,
175176 "--platform" ,
176177 options . imagePlatform ,
178+ options . load ? "--load" : undefined ,
177179 "--provenance" ,
178180 "false" ,
179181 "--metadata-file" ,
@@ -200,7 +202,6 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise<BuildI
200202 "plain" ,
201203 "." ,
202204 "--save" ,
203- options . loadImage ? "--load" : undefined ,
204205 ] . filter ( Boolean ) as string [ ] ;
205206
206207 logger . debug ( `depot ${ args . join ( " " ) } ` , { cwd : options . cwd } ) ;
@@ -290,7 +291,7 @@ interface SelfHostedBuildImageOptions {
290291 contentHash : string ;
291292 projectRef : string ;
292293 imagePlatform : string ;
293- push : boolean ;
294+ push ? : boolean ;
294295 apiUrl : string ;
295296 apiKey : string ;
296297 branchName ?: string ;
@@ -299,7 +300,7 @@ interface SelfHostedBuildImageOptions {
299300 buildEnvVars ?: Record < string , string | undefined > ;
300301 network ?: string ;
301302 builder : string ;
302- loadImage ?: boolean ;
303+ load ?: boolean ;
303304 onLog ?: ( log : string ) => void ;
304305}
305306
@@ -408,15 +409,13 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
408409
409410 const apiUrl = normalizeApiUrlForBuild ( options . apiUrl ) ;
410411 const addHost = getAddHost ( apiUrl ) ;
412+ const push = shouldPush ( options . imageTag , options . push ) ;
413+ const load = shouldLoad ( options . load , push ) ;
411414
412- // Don't push if the image tag is a local address, unless the user explicitly wants to push
413- const shouldPush = options . push
414- ? true
415- : imageTag . startsWith ( "localhost" ) ||
416- imageTag . startsWith ( "127.0.0.1" ) ||
417- imageTag . startsWith ( "0.0.0.0" )
418- ? false
419- : true ;
415+ console . log ( "imageTag" , options . imageTag ) ;
416+ console . log ( "apiUrl" , apiUrl ) ;
417+ console . log ( "push" , push ) ;
418+ console . log ( "load" , load ) ;
420419
421420 await ensureQemuRegistered ( options . imagePlatform ) ;
422421
@@ -432,8 +431,8 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
432431 options . imagePlatform ,
433432 options . network ? `--network=${ options . network } ` : undefined ,
434433 addHost ? `--add-host=${ addHost } ` : undefined ,
435- shouldPush ? "--push" : undefined ,
436- options . loadImage ? "--load" : undefined ,
434+ push ? "--push" : undefined ,
435+ load ? "--load" : undefined ,
437436 "--provenance" ,
438437 "false" ,
439438 "--metadata-file" ,
@@ -897,3 +896,43 @@ const BuildKitMetadata = z.object({
897896 "containerimage.digest" : z . string ( ) . optional ( ) ,
898897 "image.name" : z . string ( ) . optional ( ) ,
899898} ) ;
899+
900+ // Don't push if the image tag is a local address, unless the user explicitly wants to push
901+ function shouldPush ( imageTag : string , push ?: boolean ) {
902+ switch ( push ) {
903+ case true : {
904+ return true ;
905+ }
906+ case false : {
907+ return false ;
908+ }
909+ case undefined : {
910+ return imageTag . startsWith ( "localhost" ) ||
911+ imageTag . startsWith ( "127.0.0.1" ) ||
912+ imageTag . startsWith ( "0.0.0.0" )
913+ ? false
914+ : true ;
915+ }
916+ default : {
917+ assertExhaustive ( push ) ;
918+ }
919+ }
920+ }
921+
922+ // Don't load if we're pushing, unless the user explicitly wants to load
923+ function shouldLoad ( load ?: boolean , push ?: boolean ) {
924+ switch ( load ) {
925+ case true : {
926+ return true ;
927+ }
928+ case false : {
929+ return false ;
930+ }
931+ case undefined : {
932+ return push ? false : true ;
933+ }
934+ default : {
935+ assertExhaustive ( load ) ;
936+ }
937+ }
938+ }
0 commit comments