Skip to content

Added extraCACerts config #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/nervous-baboons-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---

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.
2 changes: 2 additions & 0 deletions packages/cli-v3/src/Containerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ ARG TRIGGER_DEPLOYMENT_ID
ARG TRIGGER_DEPLOYMENT_VERSION
ARG TRIGGER_CONTENT_HASH
ARG TRIGGER_PROJECT_REF
ARG NODE_EXTRA_CA_CERTS

ENV TRIGGER_PROJECT_ID=${TRIGGER_PROJECT_ID} \
TRIGGER_DEPLOYMENT_ID=${TRIGGER_DEPLOYMENT_ID} \
TRIGGER_DEPLOYMENT_VERSION=${TRIGGER_DEPLOYMENT_VERSION} \
TRIGGER_CONTENT_HASH=${TRIGGER_CONTENT_HASH} \
TRIGGER_PROJECT_REF=${TRIGGER_PROJECT_REF} \
NODE_EXTRA_CA_CERTS=${NODE_EXTRA_CA_CERTS} \
NODE_ENV=production

USER node
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-v3/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
pushImage: options.push,
selfHostedRegistry: !!options.registry,
noCache: options.noCache,
extraCACerts: resolvedConfig.config.extraCACerts,
});
}

Expand All @@ -330,6 +331,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
loadImage: options.loadImage,
buildPlatform: options.buildPlatform,
noCache: options.noCache,
extraCACerts: resolvedConfig.config.extraCACerts,
},
deploymentSpinner
);
Expand Down Expand Up @@ -779,6 +781,7 @@ type BuildAndPushImageOptions = {
loadImage: boolean;
buildPlatform: string;
noCache: boolean;
extraCACerts?: string;
};

type BuildAndPushImageResults =
Expand Down Expand Up @@ -837,6 +840,9 @@ async function buildAndPushImage(
`TRIGGER_CONTENT_HASH=${options.contentHash}`,
"--build-arg",
`TRIGGER_PROJECT_REF=${options.projectRef}`,
...(options.extraCACerts
? ["--build-arg", `NODE_EXTRA_CA_CERTS=${options.extraCACerts}`]
: []),
"-t",
`${options.registryHost}/${options.imageTag}`,
".",
Expand Down Expand Up @@ -961,6 +967,9 @@ async function buildAndPushSelfHostedImage(
`TRIGGER_CONTENT_HASH=${options.contentHash}`,
"--build-arg",
`TRIGGER_PROJECT_REF=${options.projectRef}`,
...(options.extraCACerts
? ["--build-arg", `NODE_EXTRA_CA_CERTS=${options.extraCACerts}`]
: []),
"-t",
imageRef,
".", // The build context
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-v3/src/utilities/configFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ export async function resolveConfig(path: string, config: Config): Promise<Resol
config.tsconfigPath = await findFilePath(path, "tsconfig.json");
}

if (!config.additionalFiles) {
config.additionalFiles = [];
}

if (config.extraCACerts) {
config.additionalFiles.push(config.extraCACerts);
config.extraCACerts = config.extraCACerts.replace(/^(\.[.]?\/)+/, "");
}

return config as ResolvedConfig;
}

Expand Down
1 change: 1 addition & 0 deletions packages/cli-v3/src/workers/prod/entry-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ function gatherProcessEnv() {
TERM: process.env.TERM,
NODE_PATH: process.env.NODE_PATH,
HOME: process.env.HOME,
NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS,
};

// Filter out undefined values
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/v3/schemas/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const Config = z.object({
logLevel: z.string().optional(),
enableConsoleLogging: z.boolean().optional(),
postInstall: z.string().optional(),
extraCACerts: z.string().optional(),
});

export type Config = z.infer<typeof Config>;
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/v3/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ export interface ProjectConfig {
* @example "prisma generate"
*/
postInstall?: string;

/**
* 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.
*
* @example "./certs/ca.crt"
* Note: must start with "./" and be relative to the project root.
*
*/
extraCACerts?: string;
}
Loading