Skip to content

Commit 779213c

Browse files
committed
feat(cli): use zstd for deployment images and cache
1 parent 2c3cb4a commit 779213c

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

packages/cli-v3/src/commands/deploy.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ const DeployCommandOptions = CommonCommandOptions.extend({
8383
nativeBuildServer: z.boolean().default(false),
8484
detach: z.boolean().default(false),
8585
plain: z.boolean().default(false),
86+
useZstd: z.boolean().default(true),
87+
useZstdCache: z.boolean().default(true),
88+
compressionLevel: z.number().optional(),
8689
});
8790

8891
type DeployCommandOptions = z.infer<typeof DeployCommandOptions>;
@@ -157,6 +160,24 @@ export function configureDeployCommand(program: Command) {
157160
"If provided, will save logs even for successful builds"
158161
).hideHelp()
159162
)
163+
.addOption(
164+
new CommandOption(
165+
"--use-zstd",
166+
"Use zstd compression when building the image. This will reduce image size and speed up pull times."
167+
).hideHelp()
168+
)
169+
.addOption(
170+
new CommandOption(
171+
"--use-zstd-cache",
172+
"Use zstd compression for the build cache. This will reduce cache size and speed up build times."
173+
).hideHelp()
174+
)
175+
.addOption(
176+
new CommandOption(
177+
"--compression-level <level>",
178+
"The compression level to use when building the image. The default is 3."
179+
).hideHelp()
180+
)
160181
// Local build options
161182
.addOption(
162183
new CommandOption("--force-local-build", "Deprecated alias for --local-build").implies({
@@ -499,6 +520,9 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
499520
authAccessToken: authorization.auth.accessToken,
500521
compilationPath: destination.path,
501522
buildEnvVars: buildManifest.build.env,
523+
useZstd: options.useZstd,
524+
useZstdCache: options.useZstdCache,
525+
compressionLevel: options.compressionLevel,
502526
onLog: (logMessage) => {
503527
if (options.plain || isCI) {
504528
console.log(logMessage);

packages/cli-v3/src/deploy/buildImage.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export interface BuildImageOptions {
2020
imagePlatform: string;
2121
noCache?: boolean;
2222
load?: boolean;
23+
useZstd?: boolean;
24+
useZstdCache?: boolean;
25+
compressionLevel?: number;
2326

2427
// Local build options
2528
push?: boolean;
@@ -79,6 +82,9 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
7982
buildEnvVars,
8083
network,
8184
builder,
85+
useZstd,
86+
useZstdCache,
87+
compressionLevel,
8288
onLog,
8389
} = options;
8490

@@ -105,6 +111,9 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
105111
buildEnvVars,
106112
network,
107113
builder,
114+
useZstd,
115+
useZstdCache,
116+
compressionLevel,
108117
onLog,
109118
});
110119
}
@@ -134,6 +143,8 @@ export async function buildImage(options: BuildImageOptions): Promise<BuildImage
134143
apiKey,
135144
branchName,
136145
buildEnvVars,
146+
useZstd,
147+
compressionLevel,
137148
onLog,
138149
});
139150
}
@@ -157,6 +168,8 @@ export interface DepotBuildImageOptions {
157168
noCache?: boolean;
158169
extraCACerts?: string;
159170
buildEnvVars?: Record<string, string | undefined>;
171+
useZstd?: boolean;
172+
compressionLevel?: number;
160173
onLog?: (log: string) => void;
161174
}
162175

@@ -185,6 +198,12 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise<BuildI
185198
"-f",
186199
"Containerfile",
187200
options.noCache ? "--no-cache" : undefined,
201+
options.useZstd
202+
? [
203+
"--output",
204+
`compression=zstd${options.compressionLevel ? `,level=${options.compressionLevel}` : ""}`,
205+
]
206+
: undefined,
188207
"--platform",
189208
options.imagePlatform,
190209
options.load ? "--load" : undefined,
@@ -316,11 +335,23 @@ interface SelfHostedBuildImageOptions {
316335
network?: string;
317336
builder: string;
318337
load?: boolean;
338+
useZstd?: boolean;
339+
useZstdCache?: boolean;
340+
compressionLevel?: number;
319341
onLog?: (log: string) => void;
320342
}
321343

322344
async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<BuildImageResults> {
323-
const { builder, imageTag, deploymentId, apiClient, useRegistryCache } = options;
345+
const {
346+
builder,
347+
imageTag,
348+
deploymentId,
349+
apiClient,
350+
useRegistryCache,
351+
useZstd,
352+
useZstdCache,
353+
compressionLevel,
354+
} = options;
324355

325356
// Ensure multi-platform build is supported on the local machine
326357
let builderExists = false;
@@ -500,11 +531,16 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise<Bu
500531
...(useRegistryCache
501532
? [
502533
"--cache-to",
503-
`type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${projectCacheRef}`,
534+
`type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${projectCacheRef}${
535+
useZstdCache ? ",compression=zstd" : ""
536+
}`,
504537
"--cache-from",
505538
`type=registry,ref=${projectCacheRef}`,
506539
]
507540
: []),
541+
...(useZstd
542+
? ["--output", `compression=zstd${compressionLevel ? `,level=${compressionLevel}` : ""}`]
543+
: []),
508544
"--platform",
509545
options.imagePlatform,
510546
options.network ? `--network=${options.network}` : undefined,

0 commit comments

Comments
 (0)