From 779213c77606c8e1c03b1d1f7cc1234728f634a5 Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:07:58 +0000 Subject: [PATCH 1/4] feat(cli): use zstd for deployment images and cache --- packages/cli-v3/src/commands/deploy.ts | 24 ++++++++++++++ packages/cli-v3/src/deploy/buildImage.ts | 40 ++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/packages/cli-v3/src/commands/deploy.ts b/packages/cli-v3/src/commands/deploy.ts index 818051d68d..5c558f7fe6 100644 --- a/packages/cli-v3/src/commands/deploy.ts +++ b/packages/cli-v3/src/commands/deploy.ts @@ -83,6 +83,9 @@ const DeployCommandOptions = CommonCommandOptions.extend({ nativeBuildServer: z.boolean().default(false), detach: z.boolean().default(false), plain: z.boolean().default(false), + useZstd: z.boolean().default(true), + useZstdCache: z.boolean().default(true), + compressionLevel: z.number().optional(), }); type DeployCommandOptions = z.infer; @@ -157,6 +160,24 @@ export function configureDeployCommand(program: Command) { "If provided, will save logs even for successful builds" ).hideHelp() ) + .addOption( + new CommandOption( + "--use-zstd", + "Use zstd compression when building the image. This will reduce image size and speed up pull times." + ).hideHelp() + ) + .addOption( + new CommandOption( + "--use-zstd-cache", + "Use zstd compression for the build cache. This will reduce cache size and speed up build times." + ).hideHelp() + ) + .addOption( + new CommandOption( + "--compression-level ", + "The compression level to use when building the image. The default is 3." + ).hideHelp() + ) // Local build options .addOption( new CommandOption("--force-local-build", "Deprecated alias for --local-build").implies({ @@ -499,6 +520,9 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) { authAccessToken: authorization.auth.accessToken, compilationPath: destination.path, buildEnvVars: buildManifest.build.env, + useZstd: options.useZstd, + useZstdCache: options.useZstdCache, + compressionLevel: options.compressionLevel, onLog: (logMessage) => { if (options.plain || isCI) { console.log(logMessage); diff --git a/packages/cli-v3/src/deploy/buildImage.ts b/packages/cli-v3/src/deploy/buildImage.ts index e325b58d8f..dd422b4fa6 100644 --- a/packages/cli-v3/src/deploy/buildImage.ts +++ b/packages/cli-v3/src/deploy/buildImage.ts @@ -20,6 +20,9 @@ export interface BuildImageOptions { imagePlatform: string; noCache?: boolean; load?: boolean; + useZstd?: boolean; + useZstdCache?: boolean; + compressionLevel?: number; // Local build options push?: boolean; @@ -79,6 +82,9 @@ export async function buildImage(options: BuildImageOptions): Promise; + useZstd?: boolean; + compressionLevel?: number; onLog?: (log: string) => void; } @@ -185,6 +198,12 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise void; } async function localBuildImage(options: SelfHostedBuildImageOptions): Promise { - const { builder, imageTag, deploymentId, apiClient, useRegistryCache } = options; + const { + builder, + imageTag, + deploymentId, + apiClient, + useRegistryCache, + useZstd, + useZstdCache, + compressionLevel, + } = options; // Ensure multi-platform build is supported on the local machine let builderExists = false; @@ -500,11 +531,16 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise Date: Fri, 5 Dec 2025 14:59:28 +0000 Subject: [PATCH 2/4] fix: remote build compression --- packages/cli-v3/src/deploy/buildImage.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli-v3/src/deploy/buildImage.ts b/packages/cli-v3/src/deploy/buildImage.ts index dd422b4fa6..452ae575c5 100644 --- a/packages/cli-v3/src/deploy/buildImage.ts +++ b/packages/cli-v3/src/deploy/buildImage.ts @@ -198,12 +198,12 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise Date: Tue, 9 Dec 2025 13:16:15 +0000 Subject: [PATCH 3/4] chore: misc fixes and refactor --- packages/cli-v3/src/commands/deploy.ts | 42 ++++++--- packages/cli-v3/src/deploy/buildImage.ts | 103 ++++++++++++++++++----- 2 files changed, 110 insertions(+), 35 deletions(-) diff --git a/packages/cli-v3/src/commands/deploy.ts b/packages/cli-v3/src/commands/deploy.ts index 5c558f7fe6..f4de03281c 100644 --- a/packages/cli-v3/src/commands/deploy.ts +++ b/packages/cli-v3/src/commands/deploy.ts @@ -71,7 +71,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({ saveLogs: z.boolean().default(false), skipUpdateCheck: z.boolean().default(false), skipPromotion: z.boolean().default(false), - noCache: z.boolean().default(false), + cache: z.boolean().default(true), envFile: z.string().optional(), // Local build options forceLocalBuild: z.boolean().optional(), @@ -83,9 +83,10 @@ const DeployCommandOptions = CommonCommandOptions.extend({ nativeBuildServer: z.boolean().default(false), detach: z.boolean().default(false), plain: z.boolean().default(false), - useZstd: z.boolean().default(true), - useZstdCache: z.boolean().default(true), + compression: z.enum(["zstd", "gzip"]).default("zstd"), + cacheCompression: z.enum(["zstd", "gzip"]).default("zstd"), compressionLevel: z.number().optional(), + forceCompression: z.boolean().default(true), }); type DeployCommandOptions = z.infer; @@ -162,20 +163,36 @@ export function configureDeployCommand(program: Command) { ) .addOption( new CommandOption( - "--use-zstd", - "Use zstd compression when building the image. This will reduce image size and speed up pull times." + "--compression ", + "Compression algorithm for image layers: zstd or gzip (default: zstd)" + ) + .choices(["zstd", "gzip"]) + .hideHelp() + ) + .addOption( + new CommandOption( + "--cache-compression ", + "Compression algorithm for build cache: zstd or gzip (default: zstd)" + ) + .choices(["zstd", "gzip"]) + .hideHelp() + ) + .addOption( + new CommandOption( + "--compression-level ", + "The compression level to use when building the image." ).hideHelp() ) .addOption( new CommandOption( - "--use-zstd-cache", - "Use zstd compression for the build cache. This will reduce cache size and speed up build times." + "--force-compression", + "Force recompression of all layers. Enabled by default when using zstd." ).hideHelp() ) .addOption( new CommandOption( - "--compression-level ", - "The compression level to use when building the image. The default is 3." + "--no-force-compression", + "Disable forced recompression of layers." ).hideHelp() ) // Local build options @@ -501,7 +518,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) { const buildResult = await buildImage({ isLocalBuild, useRegistryCache: options.useRegistryCache, - noCache: options.noCache, + noCache: !options.cache, deploymentId: deployment.id, deploymentVersion: deployment.version, imageTag: deployment.imageTag, @@ -520,9 +537,10 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) { authAccessToken: authorization.auth.accessToken, compilationPath: destination.path, buildEnvVars: buildManifest.build.env, - useZstd: options.useZstd, - useZstdCache: options.useZstdCache, + compression: options.compression, + cacheCompression: options.cacheCompression, compressionLevel: options.compressionLevel, + forceCompression: options.forceCompression, onLog: (logMessage) => { if (options.plain || isCI) { console.log(logMessage); diff --git a/packages/cli-v3/src/deploy/buildImage.ts b/packages/cli-v3/src/deploy/buildImage.ts index 452ae575c5..d6957bf973 100644 --- a/packages/cli-v3/src/deploy/buildImage.ts +++ b/packages/cli-v3/src/deploy/buildImage.ts @@ -20,9 +20,10 @@ export interface BuildImageOptions { imagePlatform: string; noCache?: boolean; load?: boolean; - useZstd?: boolean; - useZstdCache?: boolean; + compression?: "zstd" | "gzip"; + cacheCompression?: "zstd" | "gzip"; compressionLevel?: number; + forceCompression?: boolean; // Local build options push?: boolean; @@ -82,9 +83,10 @@ export async function buildImage(options: BuildImageOptions): Promise; - useZstd?: boolean; + compression?: "zstd" | "gzip"; compressionLevel?: number; + forceCompression?: boolean; onLog?: (log: string) => void; } @@ -193,17 +198,19 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise value) .flatMap(([key, value]) => ["--build-arg", `${key}=${value}`]); + const outputOptions = getOutputOptions({ + imageTag: undefined, // This is already handled via the --save flag + push: true, // We always push the image to the registry + compression: options.compression, + compressionLevel: options.compressionLevel, + forceCompression: options.forceCompression, + }); + const args = [ "build", "-f", "Containerfile", options.noCache ? "--no-cache" : undefined, - ...(options.useZstd - ? [ - "--output", - `compression=zstd${options.compressionLevel ? `,level=${options.compressionLevel}` : ""}`, - ] - : []), "--platform", options.imagePlatform, options.load ? "--load" : undefined, @@ -233,6 +240,8 @@ async function remoteBuildImage(options: DepotBuildImageOptions): Promise void; } @@ -348,9 +358,10 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise Date: Tue, 9 Dec 2025 14:58:38 +0000 Subject: [PATCH 4/4] add changeset --- .changeset/great-pillows-look.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/great-pillows-look.md diff --git a/.changeset/great-pillows-look.md b/.changeset/great-pillows-look.md new file mode 100644 index 0000000000..72a0589b26 --- /dev/null +++ b/.changeset/great-pillows-look.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": minor +--- + +feat(cli): enable zstd compression for deployment images