@@ -20,9 +20,10 @@ export interface BuildImageOptions {
2020 imagePlatform : string ;
2121 noCache ?: boolean ;
2222 load ?: boolean ;
23- useZstd ?: boolean ;
24- useZstdCache ?: boolean ;
23+ compression ?: "zstd" | "gzip" ;
24+ cacheCompression ?: "zstd" | "gzip" ;
2525 compressionLevel ?: number ;
26+ forceCompression ?: boolean ;
2627
2728 // Local build options
2829 push ?: boolean ;
@@ -82,9 +83,10 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
8283 buildEnvVars,
8384 network,
8485 builder,
85- useZstd ,
86- useZstdCache ,
86+ compression ,
87+ cacheCompression ,
8788 compressionLevel,
89+ forceCompression,
8890 onLog,
8991 } = options ;
9092
@@ -111,9 +113,10 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
111113 buildEnvVars,
112114 network,
113115 builder,
114- useZstd ,
115- useZstdCache ,
116+ compression ,
117+ cacheCompression ,
116118 compressionLevel,
119+ forceCompression,
117120 onLog,
118121 } ) ;
119122 }
@@ -143,8 +146,9 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
143146 apiKey,
144147 branchName,
145148 buildEnvVars,
146- useZstd ,
149+ compression ,
147150 compressionLevel,
151+ forceCompression,
148152 onLog,
149153 } ) ;
150154}
@@ -168,8 +172,9 @@ export interface DepotBuildImageOptions {
168172 noCache ?: boolean ;
169173 extraCACerts ?: string ;
170174 buildEnvVars ?: Record < string , string | undefined > ;
171- useZstd ?: boolean ;
175+ compression ?: "zstd" | "gzip" ;
172176 compressionLevel ?: number ;
177+ forceCompression ?: boolean ;
173178 onLog ?: ( log : string ) => void ;
174179}
175180
@@ -193,17 +198,19 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise<BuildI
193198 . filter ( ( [ key , value ] ) => value )
194199 . flatMap ( ( [ key , value ] ) => [ "--build-arg" , `${ key } =${ value } ` ] ) ;
195200
201+ const outputOptions = getOutputOptions ( {
202+ imageTag : undefined , // This is already handled via the --save flag
203+ push : true , // We always push the image to the registry
204+ compression : options . compression ,
205+ compressionLevel : options . compressionLevel ,
206+ forceCompression : options . forceCompression ,
207+ } ) ;
208+
196209 const args = [
197210 "build" ,
198211 "-f" ,
199212 "Containerfile" ,
200213 options . noCache ? "--no-cache" : undefined ,
201- ...( options . useZstd
202- ? [
203- "--output" ,
204- `compression=zstd${ options . compressionLevel ? `,level=${ options . compressionLevel } ` : "" } ` ,
205- ]
206- : [ ] ) ,
207214 "--platform" ,
208215 options . imagePlatform ,
209216 options . load ? "--load" : undefined ,
@@ -233,6 +240,8 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise<BuildI
233240 "plain" ,
234241 "." ,
235242 "--save" ,
243+ "--output" ,
244+ outputOptions . join ( "," ) ,
236245 ] . filter ( Boolean ) as string [ ] ;
237246
238247 logger . debug ( `depot ${ args . join ( " " ) } ` , { cwd : options . cwd } ) ;
@@ -335,9 +344,10 @@ interface SelfHostedBuildImageOptions {
335344 network ?: string ;
336345 builder : string ;
337346 load ?: boolean ;
338- useZstd ?: boolean ;
339- useZstdCache ?: boolean ;
347+ compression ?: "zstd" | "gzip" ;
348+ cacheCompression ?: "zstd" | "gzip" ;
340349 compressionLevel ?: number ;
350+ forceCompression ?: boolean ;
341351 onLog ?: ( log : string ) => void ;
342352}
343353
@@ -348,9 +358,10 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
348358 deploymentId,
349359 apiClient,
350360 useRegistryCache,
351- useZstd ,
352- useZstdCache ,
361+ compression ,
362+ cacheCompression ,
353363 compressionLevel,
364+ forceCompression,
354365 } = options ;
355366
356367 // Ensure multi-platform build is supported on the local machine
@@ -520,6 +531,14 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
520531
521532 const projectCacheRef = getProjectCacheRefFromImageTag ( imageTag ) ;
522533
534+ const outputOptions = getOutputOptions ( {
535+ imageTag,
536+ push,
537+ compression,
538+ compressionLevel,
539+ forceCompression,
540+ } ) ;
541+
523542 const args = [
524543 "buildx" ,
525544 "build" ,
@@ -532,20 +551,18 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
532551 ? [
533552 "--cache-to" ,
534553 `type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${ projectCacheRef } ${
535- useZstdCache ? ",compression=zstd" : ""
554+ cacheCompression === "zstd" ? ",compression=zstd" : ""
536555 } `,
537556 "--cache-from" ,
538557 `type=registry,ref=${ projectCacheRef } ` ,
539558 ]
540559 : [ ] ) ,
541- ...( useZstd
542- ? [ "--output" , `compression=zstd${ compressionLevel ? `,level=${ compressionLevel } ` : "" } ` ]
543- : [ ] ) ,
560+ "--output" ,
561+ outputOptions . join ( "," ) ,
544562 "--platform" ,
545563 options . imagePlatform ,
546564 options . network ? `--network=${ options . network } ` : undefined ,
547565 addHost ? `--add-host=${ addHost } ` : undefined ,
548- push ? "--push" : undefined ,
549566 load ? "--load" : undefined ,
550567 "--provenance" ,
551568 "false" ,
@@ -1108,3 +1125,43 @@ function shouldLoad(load?: boolean, push?: boolean) {
11081125 }
11091126 }
11101127}
1128+
1129+ function getOutputOptions ( {
1130+ imageTag,
1131+ push,
1132+ compression,
1133+ compressionLevel,
1134+ forceCompression,
1135+ } : {
1136+ imageTag ?: string ;
1137+ push ?: boolean ;
1138+ compression ?: "zstd" | "gzip" ;
1139+ compressionLevel ?: number ;
1140+ forceCompression ?: boolean ;
1141+ } ) : string [ ] {
1142+ // Always use OCI media types for compatibility
1143+ const outputOptions : string [ ] = [ "type=image" , "oci-mediatypes=true" ] ;
1144+
1145+ if ( imageTag ) {
1146+ outputOptions . push ( `name=${ imageTag } ` ) ;
1147+ }
1148+
1149+ if ( push ) {
1150+ outputOptions . push ( "push=true" ) ;
1151+ }
1152+
1153+ // Only add compression args when using zstd (gzip is the default, no args needed)
1154+ if ( compression === "zstd" ) {
1155+ outputOptions . push ( "compression=zstd" ) ;
1156+
1157+ if ( compressionLevel !== undefined ) {
1158+ outputOptions . push ( `compression-level=${ compressionLevel } ` ) ;
1159+ }
1160+ }
1161+
1162+ if ( forceCompression ) {
1163+ outputOptions . push ( "force-compression=true" ) ;
1164+ }
1165+
1166+ return outputOptions ;
1167+ }
0 commit comments