Skip to content

Commit 1119e9c

Browse files
developerfredclaude
andcommitted
fix(cli): apply extraCACerts on deploy
deploy never passed extraCACerts to buildImage, so the generated Containerfile set NODE_EXTRA_CA_CERTS to an empty string, and the CA file was not copied into the image either. Copy the CA file into the build output and pass its in-image path as the NODE_EXTRA_CA_CERTS build arg. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 753ede6 commit 1119e9c

5 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fix `extraCACerts` in `trigger.config.ts` having no effect on deployed tasks. The CA file is now included in the deployed image and `NODE_EXTRA_CA_CERTS` points at it, so self-signed or corporate certificates are trusted at runtime.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
} from "../cli/common.js";
5151
import { loadConfig } from "../config.js";
5252
import { authenticateForDeploy, userIdForDeploy } from "../deploy/auth.js";
53-
import { buildImage } from "../deploy/buildImage.js";
53+
import { buildImage, resolveExtraCACertsImagePath } from "../deploy/buildImage.js";
5454
import {
5555
checkLogsForErrors,
5656
checkLogsForWarnings,
@@ -765,6 +765,10 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
765765
externalBuildProjectId: deployment.externalBuildData?.projectId,
766766
projectId: projectClient.id,
767767
projectRef: resolvedConfig.project,
768+
extraCACerts: resolveExtraCACertsImagePath(
769+
resolvedConfig.extraCACerts,
770+
resolvedConfig.workingDir
771+
),
768772
apiUrl: projectClient.client.apiURL,
769773
apiKey: projectClient.client.accessToken!,
770774
apiClient: projectClient.client,

‎packages/cli-v3/src/config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ async function autoDetectDirs(workingDir: string): Promise<string[]> {
301301
}
302302

303303
function validateConfig(config: TriggerConfig, warn = true) {
304+
if (config.extraCACerts) {
305+
// The CA file must be inside the build output so the image can point NODE_EXTRA_CA_CERTS at it
306+
config.build ??= {};
307+
config.build.extensions ??= [];
308+
config.build.extensions.push(additionalFiles({ files: [config.extraCACerts] }));
309+
}
310+
304311
if (config.additionalFiles && config.additionalFiles.length > 0) {
305312
warn &&
306313
prettyWarning(

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TOOLCHAIN_PACKAGES,
1111
formatCommandForDiagnostics,
1212
generateContainerfile,
13+
resolveExtraCACertsImagePath,
1314
} from "./buildImage.js";
1415

1516
describe("formatCommandForDiagnostics", () => {
@@ -53,6 +54,20 @@ const images: Array<[BuildRuntime, string, string]> = [
5354
],
5455
];
5556

57+
describe("resolveExtraCACertsImagePath", () => {
58+
it("returns undefined when no CA file is configured", () => {
59+
expect(resolveExtraCACertsImagePath(undefined, "/project")).toBeUndefined();
60+
});
61+
62+
it("maps a project-relative path into /app", () => {
63+
expect(resolveExtraCACertsImagePath("./certs/ca.crt", "/project")).toBe("/app/certs/ca.crt");
64+
});
65+
66+
it("strips leading parent segments the same way additionalFiles does", () => {
67+
expect(resolveExtraCACertsImagePath("../shared/ca.crt", "/project")).toBe("/app/shared/ca.crt");
68+
});
69+
});
70+
5671
describe("generateContainerfile", () => {
5772
it.each(images)("uses the pinned published base images for %s", async (runtime, base, build) => {
5873
const containerfile = await generateContainerfile({

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { depot } from "@depot/cli";
33
import { x } from "tinyexec";
44
import type { BuildManifest, BuildRuntime } from "@trigger.dev/core/v3/schemas";
55
import { networkInterfaces } from "os";
6-
import { join } from "path";
6+
import { join, relative, resolve, sep } from "path";
77
import { safeReadJSONFile } from "../utilities/fileSystem.js";
88
import { readFileSync } from "fs";
99

@@ -55,6 +55,23 @@ export interface BuildImageOptions {
5555
deploymentSpinner?: any; // Replace 'any' with the actual type if known
5656
}
5757

58+
/**
59+
* Where the CA file ends up inside the image. The build copies it into /app using the same layout
60+
* as additionalFiles (path relative to the project root, with leading `..` segments stripped).
61+
*/
62+
export function resolveExtraCACertsImagePath(extraCACerts: string | undefined, workingDir: string) {
63+
if (!extraCACerts) {
64+
return undefined;
65+
}
66+
67+
const relativePath = relative(workingDir, resolve(workingDir, extraCACerts))
68+
.split(sep)
69+
.filter((segment) => segment !== "..")
70+
.join("/");
71+
72+
return `/app/${relativePath}`;
73+
}
74+
5875
export async function buildImage(options: BuildImageOptions): Promise<BuildImageResults> {
5976
const {
6077
isLocalBuild,

0 commit comments

Comments
 (0)