Repository navigation
feat(webapp,cli): let self-hosted instances require deploy base images #5005
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
Open
brentshulman-silkline
wants to merge
8
commits into
triggerdotdev:main
Choose a base branch
from
brentshulman-silkline:feat/instance-deploy-base-images
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+444
−9
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d3fb37
feat(webapp,cli): let self-hosted instances require deploy base images
brentshulman-silkline 2a0c5ba
feat(cli,webapp): harden instance deploy base images
nicktrn d5c1239
feat(cli,webapp): enforce instance base images end to end
nicktrn 701591d
fix(webapp,cli): reject native builds server-side when base images ar…
nicktrn a8dfe94
chore: merge main into instance deploy base images
nicktrn fbfdb57
refactor(cli,webapp): simplify instance base image handling
nicktrn a6bd65a
docs: trim custom base images section
nicktrn 0549f55
fix(cli): reject from-bundle deploys that need instance base images
nicktrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@trigger.dev/core": patch | ||
| "trigger.dev": patch | ||
| --- | ||
|
|
||
| Self-hosted instances can require custom deploy base images per runtime via the new `DEPLOY_BASE_IMAGES` and `DEPLOY_BUILD_BASE_IMAGES` webapp settings. The CLI builds on the images the instance specifies, and older CLIs are rejected with an upgrade message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { BuildRuntime, DeployBaseImageRef } from "@trigger.dev/core/v3"; | ||
|
|
||
| type BaseImageMap = Partial<Record<BuildRuntime, string>>; | ||
|
|
||
| export function parseDeployBaseImages( | ||
| value: string | undefined, | ||
| envVarName: string | ||
| ): { images: BaseImageMap; errors: string[] } { | ||
| const images: BaseImageMap = {}; | ||
| const errors: string[] = []; | ||
|
|
||
| if (!value) { | ||
| return { images, errors }; | ||
| } | ||
|
|
||
| for (const segment of value.split(",").map((s) => s.trim())) { | ||
| if (!segment) { | ||
| continue; | ||
| } | ||
|
|
||
| const fail = (reason: string) => errors.push(`${envVarName}: ${reason} in "${segment}"`); | ||
|
|
||
| const separator = segment.indexOf("="); | ||
| if (separator === -1) { | ||
| fail("expected runtime=image"); | ||
| continue; | ||
| } | ||
|
|
||
| const runtimeName = segment.slice(0, separator).trim(); | ||
| const image = segment.slice(separator + 1).trim(); | ||
|
|
||
| if (runtimeName === "node") { | ||
| fail('runtime "node" is an alias; use the concrete runtime (node-22, node-24, node-26)'); | ||
| continue; | ||
| } | ||
|
|
||
| const runtime = BuildRuntime.safeParse(runtimeName); | ||
| if (!runtime.success) { | ||
| fail(`unknown runtime "${runtimeName}" (expected one of ${BuildRuntime.options.join(", ")})`); | ||
| continue; | ||
| } | ||
|
|
||
| if (!image) { | ||
| fail("missing image"); | ||
| continue; | ||
| } | ||
|
|
||
| if (!DeployBaseImageRef.safeParse(image).success) { | ||
| fail("image must be image@sha256:<64 hex chars> with no whitespace before the digest"); | ||
| continue; | ||
| } | ||
|
|
||
| if (runtime.data in images) { | ||
| fail(`duplicate runtime "${runtimeName}"`); | ||
| continue; | ||
| } | ||
|
|
||
| images[runtime.data] = image; | ||
| } | ||
|
|
||
| return { images, errors }; | ||
| } | ||
|
|
||
| export function resolveDeployBaseImages( | ||
| runtime: string | null | undefined, | ||
| config: { base: BaseImageMap; buildBase: BaseImageMap } | ||
| ): { base?: string; buildBase?: string } | undefined { | ||
| const parsedRuntime = BuildRuntime.safeParse(runtime); | ||
| if (!parsedRuntime.success) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const base = config.base[parsedRuntime.data]; | ||
| const buildBase = config.buildBase[parsedRuntime.data]; | ||
|
|
||
| return base || buildBase ? { base, buildBase } : undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { parseDeployBaseImages, resolveDeployBaseImages } from "~/v3/deployBaseImages.server"; | ||
|
nicktrn marked this conversation as resolved.
|
||
|
|
||
| const digestA = `sha256:${"a".repeat(64)}`; | ||
| const digestB = `sha256:${"b".repeat(64)}`; | ||
| const digestC = `sha256:${"c".repeat(64)}`; | ||
|
|
||
| describe("parseDeployBaseImages", () => { | ||
| it("returns an empty map for undefined and empty values", () => { | ||
| const empty = { images: {}, errors: [] }; | ||
| expect(parseDeployBaseImages(undefined, "DEPLOY_BASE_IMAGES")).toEqual(empty); | ||
| expect(parseDeployBaseImages("", "DEPLOY_BASE_IMAGES")).toEqual(empty); | ||
| expect(parseDeployBaseImages(" , ,", "DEPLOY_BASE_IMAGES")).toEqual(empty); | ||
| }); | ||
|
|
||
| it("parses multiple entries and trims whitespace", () => { | ||
| expect( | ||
| parseDeployBaseImages( | ||
| ` node-24 = acme/node-fips:24@${digestA} , bun=acme/bun:1@${digestB},`, | ||
| "DEPLOY_BASE_IMAGES" | ||
| ) | ||
| ).toEqual({ | ||
| images: { | ||
| "node-24": `acme/node-fips:24@${digestA}`, | ||
| bun: `acme/bun:1@${digestB}`, | ||
| }, | ||
| errors: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("accepts a registry with a port and a tag before the digest", () => { | ||
| const image = `registry.example.com:5000/ns/img:tag@${digestA}`; | ||
| expect(parseDeployBaseImages(`node-24=${image}`, "DEPLOY_BASE_IMAGES")).toEqual({ | ||
| images: { "node-24": image }, | ||
| errors: [], | ||
| }); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["missing =", "garbage"], | ||
| ["unknown runtime", `node-23=acme/node:23@${digestA}`], | ||
| ["node alias", `node=acme/node:24@${digestA}`], | ||
| ["empty image", "node-24="], | ||
| ["missing digest", "node-24=acme/node:24"], | ||
| ["flag before image", `node-24=--platform=linux/arm64 acme/node@${digestA}`], | ||
| ["bare digest", `node-24=@${digestA}`], | ||
| ["newline in image", `node-24=acme/node\nx@${digestA}`], | ||
| ["duplicate runtime", `node-24=acme/a@${digestA},node-24=acme/b@${digestB}`], | ||
| ])("reports an error naming the env var and segment: %s", (_name, value) => { | ||
| const segments = value.split(","); | ||
| const offending = segments[segments.length - 1]!.trim(); | ||
|
|
||
| const { images, errors } = parseDeployBaseImages( | ||
| `node-22=acme/ok@${digestC},${value}`, | ||
| "DEPLOY_BUILD_BASE_IMAGES" | ||
| ); | ||
|
|
||
| expect(images["node-22"]).toBe(`acme/ok@${digestC}`); | ||
| expect(errors).toHaveLength(1); | ||
| expect(errors[0]).toContain("DEPLOY_BUILD_BASE_IMAGES"); | ||
| expect(errors[0]).toContain(offending); | ||
| }); | ||
|
|
||
| it("explains that node is an alias", () => { | ||
| const { errors } = parseDeployBaseImages(`node=acme/node@${digestA}`, "DEPLOY_BASE_IMAGES"); | ||
| expect(errors[0]).toContain('runtime "node" is an alias; use the concrete runtime'); | ||
| }); | ||
|
|
||
| it("reports every bad segment", () => { | ||
| const { errors } = parseDeployBaseImages( | ||
| `garbage,node-23=acme/node@${digestA},bun=acme/bun`, | ||
| "DEPLOY_BASE_IMAGES" | ||
| ); | ||
| expect(errors).toHaveLength(3); | ||
| expect(errors[0]).toContain("garbage"); | ||
| expect(errors[1]).toContain("node-23"); | ||
| expect(errors[2]).toContain("bun=acme/bun"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveDeployBaseImages", () => { | ||
| const base = { "node-26": `acme/node-fips:26@${digestA}` } as const; | ||
| const buildBase = { "node-26": `acme/node:26-dev@${digestB}` } as const; | ||
|
|
||
| it("returns undefined for a missing or unknown runtime", () => { | ||
| expect(resolveDeployBaseImages("node-23", { base, buildBase })).toBeUndefined(); | ||
| expect(resolveDeployBaseImages(null, { base, buildBase })).toBeUndefined(); | ||
| expect(resolveDeployBaseImages(undefined, { base, buildBase })).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns undefined when the runtime has no entries", () => { | ||
| expect(resolveDeployBaseImages("bun", { base, buildBase })).toBeUndefined(); | ||
| expect(resolveDeployBaseImages("node-26", { base: {}, buildBase: {} })).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns both images", () => { | ||
| expect(resolveDeployBaseImages("node-26", { base, buildBase })).toEqual({ | ||
| base: base["node-26"], | ||
| buildBase: buildBase["node-26"], | ||
| }); | ||
| }); | ||
|
|
||
| it("returns only the base image", () => { | ||
| expect(resolveDeployBaseImages("node-26", { base, buildBase: {} })).toEqual({ | ||
| base: base["node-26"], | ||
| }); | ||
| }); | ||
|
|
||
| it("returns only the build base image", () => { | ||
| expect(resolveDeployBaseImages("node-26", { base: {}, buildBase })).toEqual({ | ||
| buildBase: buildBase["node-26"], | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.