diff --git a/.changeset/funny-ligers-wonder.md b/.changeset/funny-ligers-wonder.md new file mode 100644 index 0000000000..7f552d1296 --- /dev/null +++ b/.changeset/funny-ligers-wonder.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": patch +--- + +Added external cache support for local image builds diff --git a/packages/cli-v3/src/commands/deploy.ts b/packages/cli-v3/src/commands/deploy.ts index 36f35d442e..1e6e291113 100644 --- a/packages/cli-v3/src/commands/deploy.ts +++ b/packages/cli-v3/src/commands/deploy.ts @@ -64,6 +64,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({ envFile: z.string().optional(), // Local build options forceLocalBuild: z.boolean().optional(), + useRegistryCache: z.boolean().default(false), network: z.enum(["default", "none", "host"]).optional(), push: z.boolean().optional(), builder: z.string().default("trigger"), @@ -112,11 +113,19 @@ export function configureDeployCommand(program: Command) { "Skip promoting the deployment to the current deployment for the environment." ) ) + .addOption( + new CommandOption( + "--use-registry-cache", + "Use the registry cache when building the image. The registry must be supported as a cache storage backend." + ).hideHelp() + ) .addOption( new CommandOption( "--no-cache", "Do not use the cache when building the image. This will slow down the build process but can be useful if you are experiencing issues with the cache." - ).hideHelp() + ) + .conflicts("useRegistryCache") + .hideHelp() ) .addOption( new CommandOption("--load", "Load the built image into your local docker").hideHelp() @@ -418,6 +427,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) { const buildResult = await buildImage({ isLocalBuild, + useRegistryCache: options.useRegistryCache, noCache: options.noCache, deploymentId: deployment.id, deploymentVersion: deployment.version, diff --git a/packages/cli-v3/src/deploy/buildImage.ts b/packages/cli-v3/src/deploy/buildImage.ts index 7aed546862..6f044c8a7d 100644 --- a/packages/cli-v3/src/deploy/buildImage.ts +++ b/packages/cli-v3/src/deploy/buildImage.ts @@ -16,6 +16,7 @@ import { CliApiClient } from "../apiClient.js"; export interface BuildImageOptions { // Common options isLocalBuild: boolean; + useRegistryCache?: boolean; imagePlatform: string; noCache?: boolean; load?: boolean; @@ -53,6 +54,7 @@ export interface BuildImageOptions { export async function buildImage(options: BuildImageOptions): Promise { const { isLocalBuild, + useRegistryCache, imagePlatform, noCache, push, @@ -94,6 +96,7 @@ export async function buildImage(options: BuildImageOptions): Promise; network?: string; @@ -316,7 +320,7 @@ interface SelfHostedBuildImageOptions { } async function localBuildImage(options: SelfHostedBuildImageOptions): Promise { - const { builder, imageTag, deploymentId, apiClient } = options; + const { builder, imageTag, deploymentId, apiClient, useRegistryCache } = options; // Ensure multi-platform build is supported on the local machine let builderExists = false; @@ -483,6 +487,8 @@ async function localBuildImage(options: SelfHostedBuildImageOptions): Promise