Skip to content

Commit 87e46d4

Browse files
authored
projects now have a dedicated build server (#1281)
1 parent 022bbe1 commit 87e46d4

File tree

7 files changed

+65
-23
lines changed

7 files changed

+65
-23
lines changed

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const EnvironmentSchema = z.object({
114114
DEPOT_TOKEN: z.string().optional(),
115115
DEPOT_PROJECT_ID: z.string().optional(),
116116
DEPOT_ORG_ID: z.string().optional(),
117+
DEPOT_REGION: z.string().default("us-east-1"),
117118
CONTAINER_REGISTRY_ORIGIN: z.string().optional(),
118119
CONTAINER_REGISTRY_USERNAME: z.string().optional(),
119120
CONTAINER_REGISTRY_PASSWORD: z.string().optional(),
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { depot } from "@depot/sdk-node";
2+
import { Project } from "@trigger.dev/database";
3+
import { prisma } from "~/db.server";
24
import { env } from "~/env.server";
35

4-
export async function createRemoteImageBuild() {
6+
export async function createRemoteImageBuild(project: Project) {
57
if (!env.DEPOT_TOKEN || !env.DEPOT_PROJECT_ID) {
68
return;
79
}
810

11+
const builderProjectId = await createBuilderProjectIfNotExists(project);
12+
913
const result = await depot.build.v1.BuildService.createBuild(
10-
{ projectId: env.DEPOT_PROJECT_ID },
14+
{ projectId: builderProjectId },
1115
{
1216
headers: {
1317
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
@@ -16,8 +20,40 @@ export async function createRemoteImageBuild() {
1620
);
1721

1822
return {
19-
projectId: env.DEPOT_PROJECT_ID,
23+
projectId: builderProjectId,
2024
buildToken: result.buildToken,
2125
buildId: result.buildId,
2226
};
2327
}
28+
29+
async function createBuilderProjectIfNotExists(project: Project) {
30+
if (project.builderProjectId) {
31+
return project.builderProjectId;
32+
}
33+
34+
const result = await depot.core.v1.ProjectService.createProject(
35+
{
36+
name: `${env.APP_ENV} ${project.externalRef}`,
37+
organizationId: env.DEPOT_ORG_ID,
38+
regionId: env.DEPOT_REGION,
39+
},
40+
{
41+
headers: {
42+
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
43+
},
44+
}
45+
);
46+
47+
if (!result.project) {
48+
throw new Error("Failed to create builder project");
49+
}
50+
51+
await prisma.project.update({
52+
where: { id: project.id },
53+
data: {
54+
builderProjectId: result.project.projectId,
55+
},
56+
});
57+
58+
return result.project.projectId;
59+
}

apps/webapp/app/v3/services/initializeDeployment.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class InitializeDeploymentService extends BaseService {
2929
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);
3030

3131
// Try and create a depot build and get back the external build data
32-
const externalBuildData = await createRemoteImageBuild();
32+
const externalBuildData = await createRemoteImageBuild(environment.project);
3333

3434
const triggeredBy = payload.userId
3535
? await this._prisma.user.findUnique({

apps/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@codemirror/view": "^6.5.0",
4646
"@conform-to/react": "^0.6.1",
4747
"@conform-to/zod": "^0.6.1",
48-
"@depot/sdk-node": "^0.5.0",
48+
"@depot/sdk-node": "^1.0.0",
4949
"@headlessui/react": "^1.7.8",
5050
"@heroicons/react": "^2.0.12",
5151
"@internationalized/date": "^3.5.1",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Project" ADD COLUMN "builderProjectId" TEXT;

packages/database/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ model Project {
441441
442442
version ProjectVersion @default(V2)
443443
444+
builderProjectId String?
445+
444446
environments RuntimeEnvironment[]
445447
endpoints Endpoint[]
446448
jobs Job[]

pnpm-lock.yaml

Lines changed: 19 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)