-
-
Notifications
You must be signed in to change notification settings - Fork 896
feat(deployments): --native-build-server support for the deploy command
#2702
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
myftija
wants to merge
21
commits into
main
Choose a base branch
from
cli-deploy-with-native-builders
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.
+2,574
−592
Open
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b27091b
Support native build server for deployments with the cli
myftija 83bd51d
Add changeset
myftija d645d71
changelog
myftija bf56f5a
Avoid doing a db migration for the deployment table for now
myftija 7191e0d
Get rid of clack's `taskLog`, not working reliably
myftija e2d5e83
Show a separate spinner during deployment init
myftija b9330ed
Return on process exit
myftija 81f63ba
Pass in config file path
myftija 6337613
Make ARTIFACTS_OBJECT_STORE_BUCKET optional
myftija 85fd901
Revert @clack/prompts to old version, latest version causes spinner i…
myftija d3cb09f
Add --plain option for simpler build server logs
myftija ec518ec
Remove snipper custom cancel message, not supported in old ver
myftija ba49783
Remove custom spacing, also not supported n old ver
myftija fc2b733
Switch logs printing to a simple console log in favor of tighter line…
myftija 91ab549
Ignore SecretsUsedInArgOrEnv docker build warnings, often misleading …
myftija 164a178
Add hint about deployment promotion
myftija f0cd177
Consolidate failed log messages
myftija be69de3
Drop the `force` from `--force-local-build`
myftija 5228299
Add changeset
myftija 4365889
Update the original changeset to a minor release
myftija 973a04d
Revert prerelease changeset config change
myftija 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| { | ||
| "$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
| "changelog": [ | ||
| "@remix-run/changelog-github", | ||
| { | ||
| "repo": "triggerdotdev/trigger.dev" | ||
| } | ||
| ], | ||
| "changelog": "@changesets/cli/changelog", | ||
| "commit": false, | ||
| "fixed": [["@trigger.dev/*", "trigger.dev"]], | ||
| "linked": [], | ||
|
|
||
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": patch | ||
myftija marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "@trigger.dev/core": patch | ||
| --- | ||
|
|
||
| Added support for native build server builds in the deploy command | ||
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,78 @@ | ||
| import { type ActionFunctionArgs, json } from "@remix-run/server-runtime"; | ||
| import { | ||
| type CreateArtifactResponseBody, | ||
| CreateArtifactRequestBody, | ||
| tryCatch, | ||
| } from "@trigger.dev/core/v3"; | ||
| import { authenticateRequest } from "~/services/apiAuth.server"; | ||
| import { logger } from "~/services/logger.server"; | ||
| import { ArtifactsService } from "~/v3/services/artifacts.server"; | ||
|
|
||
| export async function action({ request }: ActionFunctionArgs) { | ||
| if (request.method.toUpperCase() !== "POST") { | ||
| return json({ error: "Method Not Allowed" }, { status: 405 }); | ||
| } | ||
|
|
||
| const authenticationResult = await authenticateRequest(request, { | ||
| apiKey: true, | ||
| organizationAccessToken: false, | ||
| personalAccessToken: false, | ||
| }); | ||
|
|
||
| if (!authenticationResult || !authenticationResult.result.ok) { | ||
| logger.info("Invalid or missing api key", { url: request.url }); | ||
| return json({ error: "Invalid or Missing API key" }, { status: 401 }); | ||
| } | ||
|
|
||
| const [, rawBody] = await tryCatch(request.json()); | ||
| const body = CreateArtifactRequestBody.safeParse(rawBody ?? {}); | ||
|
|
||
| if (!body.success) { | ||
| return json({ error: "Invalid request body", issues: body.error.issues }, { status: 400 }); | ||
| } | ||
|
|
||
| const { environment: authenticatedEnv } = authenticationResult.result; | ||
|
|
||
| const service = new ArtifactsService(); | ||
| return await service | ||
| .createArtifact(body.data.type, authenticatedEnv, body.data.contentLength) | ||
| .match( | ||
| (result) => { | ||
| return json( | ||
| { | ||
| artifactKey: result.artifactKey, | ||
| uploadUrl: result.uploadUrl, | ||
| uploadFields: result.uploadFields, | ||
| expiresAt: result.expiresAt.toISOString(), | ||
| } satisfies CreateArtifactResponseBody, | ||
| { status: 201 } | ||
| ); | ||
| }, | ||
| (error) => { | ||
| switch (error.type) { | ||
| case "artifact_size_exceeds_limit": { | ||
| logger.warn("Artifact size exceeds limit", { error }); | ||
| return json( | ||
| { | ||
| error: `Artifact size (${error.contentLength} bytes) exceeds the allowed limit of ${error.sizeLimit} bytes`, | ||
| }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
| case "failed_to_create_presigned_post": { | ||
| logger.error("Failed to create presigned POST", { error }); | ||
| return json({ error: "Failed to generate artifact upload URL" }, { status: 500 }); | ||
| } | ||
| case "artifacts_bucket_not_configured": { | ||
| logger.error("Artifacts bucket not configured", { error }); | ||
| return json({ error: "Internal server error" }, { status: 500 }); | ||
| } | ||
| default: { | ||
| error satisfies never; | ||
| logger.error("Failed creating artifact", { error }); | ||
| return json({ error: "Internal server error" }, { status: 500 }); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| } |
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,92 @@ | ||
| import type { AuthenticatedEnvironment } from "~/services/apiAuth.server"; | ||
| import { BaseService } from "./baseService.server"; | ||
| import { env } from "~/env.server"; | ||
| import { createPresignedPost } from "@aws-sdk/s3-presigned-post"; | ||
| import { S3Client } from "@aws-sdk/client-s3"; | ||
| import { customAlphabet } from "nanoid"; | ||
| import { errAsync, fromPromise } from "neverthrow"; | ||
|
|
||
| const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", 24); | ||
| const objectStoreClient = | ||
| env.ARTIFACTS_OBJECT_STORE_ACCESS_KEY_ID && | ||
| env.ARTIFACTS_OBJECT_STORE_SECRET_ACCESS_KEY && | ||
| env.ARTIFACTS_OBJECT_STORE_BASE_URL | ||
| ? new S3Client({ | ||
| credentials: { | ||
| accessKeyId: env.ARTIFACTS_OBJECT_STORE_ACCESS_KEY_ID, | ||
| secretAccessKey: env.ARTIFACTS_OBJECT_STORE_SECRET_ACCESS_KEY, | ||
| }, | ||
| region: env.ARTIFACTS_OBJECT_STORE_REGION, | ||
| endpoint: env.ARTIFACTS_OBJECT_STORE_BASE_URL, | ||
| forcePathStyle: true, | ||
| }) | ||
| : new S3Client(); | ||
|
|
||
| const artifactKeyPrefixByType = { | ||
| deployment_context: "deployments", | ||
| } as const; | ||
| const artifactBytesSizeLimitByType = { | ||
| deployment_context: 100 * 1024 * 1024, // 100MB | ||
| } as const; | ||
|
|
||
| export class ArtifactsService extends BaseService { | ||
| private readonly bucket = env.ARTIFACTS_OBJECT_STORE_BUCKET; | ||
|
|
||
| public createArtifact( | ||
| type: "deployment_context", | ||
| authenticatedEnv: AuthenticatedEnvironment, | ||
| contentLength?: number | ||
| ) { | ||
| const limit = artifactBytesSizeLimitByType[type]; | ||
|
|
||
| // this is just a validation using client-side data | ||
| // the actual limit will be enforced by S3 | ||
| if (contentLength && contentLength > limit) { | ||
| return errAsync({ | ||
| type: "artifact_size_exceeds_limit" as const, | ||
| contentLength, | ||
| sizeLimit: limit, | ||
| }); | ||
| } | ||
|
|
||
| const uniqueId = nanoid(); | ||
| const key = `${artifactKeyPrefixByType[type]}/${authenticatedEnv.project.externalRef}/${authenticatedEnv.slug}/${uniqueId}.tar.gz`; | ||
|
|
||
| return this.createPresignedPost(key, limit, contentLength).map((result) => ({ | ||
| artifactKey: key, | ||
| uploadUrl: result.url, | ||
| uploadFields: result.fields, | ||
| expiresAt: result.expiresAt, | ||
| })); | ||
| } | ||
|
|
||
| private createPresignedPost(key: string, sizeLimit: number, contentLength?: number) { | ||
| if (!this.bucket) { | ||
| return errAsync({ | ||
| type: "artifacts_bucket_not_configured" as const, | ||
| }); | ||
| } | ||
|
|
||
| const ttlSeconds = 300; // 5 minutes | ||
| const expiresAt = new Date(Date.now() + ttlSeconds * 1000); | ||
|
|
||
| return fromPromise( | ||
| createPresignedPost(objectStoreClient, { | ||
| Bucket: this.bucket, | ||
| Key: key, | ||
| Conditions: [["content-length-range", 0, sizeLimit]], | ||
| Fields: { | ||
| "Content-Type": "application/gzip", | ||
| }, | ||
| Expires: ttlSeconds, | ||
| }), | ||
| (error) => ({ | ||
| type: "failed_to_create_presigned_post" as const, | ||
| cause: error, | ||
| }) | ||
| ).map((result) => ({ | ||
| ...result, | ||
| expiresAt, | ||
| })); | ||
| } | ||
| } |
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.