Skip to content

Commit e417aca

Browse files
gautamsinicktrn
andauthored
v3: add extraCACerts config (#1214)
* Added extraCACerts config to help with self signed/private ca cert chain * changeset * Update changeset * resolved pr comments --------- Co-authored-by: nicktrn <[email protected]>
1 parent 5a3b4a4 commit e417aca

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

.changeset/nervous-baboons-sin.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Added config option extraCACerts to ProjectConfig type. This copies the ca file along with additionalFiles and sets NODE_EXTRA_CA_CERTS environment variable in built image as well as running the task.

packages/cli-v3/src/Containerfile.prod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ ARG TRIGGER_DEPLOYMENT_ID
4343
ARG TRIGGER_DEPLOYMENT_VERSION
4444
ARG TRIGGER_CONTENT_HASH
4545
ARG TRIGGER_PROJECT_REF
46+
ARG NODE_EXTRA_CA_CERTS
4647

4748
ENV TRIGGER_PROJECT_ID=${TRIGGER_PROJECT_ID} \
4849
TRIGGER_DEPLOYMENT_ID=${TRIGGER_DEPLOYMENT_ID} \
4950
TRIGGER_DEPLOYMENT_VERSION=${TRIGGER_DEPLOYMENT_VERSION} \
5051
TRIGGER_CONTENT_HASH=${TRIGGER_CONTENT_HASH} \
5152
TRIGGER_PROJECT_REF=${TRIGGER_PROJECT_REF} \
53+
NODE_EXTRA_CA_CERTS=${NODE_EXTRA_CA_CERTS} \
5254
NODE_ENV=production
5355

5456
USER node

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
304304
pushImage: options.push,
305305
selfHostedRegistry: !!options.registry,
306306
noCache: options.noCache,
307+
extraCACerts: resolvedConfig.config.extraCACerts,
307308
});
308309
}
309310

@@ -330,6 +331,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
330331
loadImage: options.loadImage,
331332
buildPlatform: options.buildPlatform,
332333
noCache: options.noCache,
334+
extraCACerts: resolvedConfig.config.extraCACerts,
333335
},
334336
deploymentSpinner
335337
);
@@ -779,6 +781,7 @@ type BuildAndPushImageOptions = {
779781
loadImage: boolean;
780782
buildPlatform: string;
781783
noCache: boolean;
784+
extraCACerts?: string;
782785
};
783786

784787
type BuildAndPushImageResults =
@@ -837,6 +840,9 @@ async function buildAndPushImage(
837840
`TRIGGER_CONTENT_HASH=${options.contentHash}`,
838841
"--build-arg",
839842
`TRIGGER_PROJECT_REF=${options.projectRef}`,
843+
...(options.extraCACerts
844+
? ["--build-arg", `NODE_EXTRA_CA_CERTS=${options.extraCACerts}`]
845+
: []),
840846
"-t",
841847
`${options.registryHost}/${options.imageTag}`,
842848
".",
@@ -961,6 +967,9 @@ async function buildAndPushSelfHostedImage(
961967
`TRIGGER_CONTENT_HASH=${options.contentHash}`,
962968
"--build-arg",
963969
`TRIGGER_PROJECT_REF=${options.projectRef}`,
970+
...(options.extraCACerts
971+
? ["--build-arg", `NODE_EXTRA_CA_CERTS=${options.extraCACerts}`]
972+
: []),
964973
"-t",
965974
imageRef,
966975
".", // The build context

packages/cli-v3/src/utilities/configFiles.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ export async function resolveConfig(path: string, config: Config): Promise<Resol
247247
config.tsconfigPath = await findFilePath(path, "tsconfig.json");
248248
}
249249

250+
if (!config.additionalFiles) {
251+
config.additionalFiles = [];
252+
}
253+
254+
if (config.extraCACerts) {
255+
config.additionalFiles.push(config.extraCACerts);
256+
config.extraCACerts = config.extraCACerts.replace(/^(\.[.]?\/)+/, "");
257+
}
258+
250259
return config as ResolvedConfig;
251260
}
252261

packages/cli-v3/src/workers/prod/entry-point.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ function gatherProcessEnv() {
14851485
TERM: process.env.TERM,
14861486
NODE_PATH: process.env.NODE_PATH,
14871487
HOME: process.env.HOME,
1488+
NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS,
14881489
};
14891490

14901491
// Filter out undefined values

packages/core/src/v3/schemas/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export const Config = z.object({
206206
logLevel: z.string().optional(),
207207
enableConsoleLogging: z.boolean().optional(),
208208
postInstall: z.string().optional(),
209+
extraCACerts: z.string().optional(),
209210
});
210211

211212
export type Config = z.infer<typeof Config>;

packages/core/src/v3/types/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,13 @@ export interface ProjectConfig {
8282
* @example "prisma generate"
8383
*/
8484
postInstall?: string;
85+
86+
/**
87+
* CA Cert file to be added to NODE_EXTRA_CA_CERT environment variable in, useful in use with self signed cert in the trigger.dev environment.
88+
*
89+
* @example "./certs/ca.crt"
90+
* Note: must start with "./" and be relative to the project root.
91+
*
92+
*/
93+
extraCACerts?: string;
8594
}

0 commit comments

Comments
 (0)