Skip to content
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
1 change: 1 addition & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const EnvironmentSchema = z.object({
DEPOT_TOKEN: z.string().optional(),
DEPOT_PROJECT_ID: z.string().optional(),
DEPOT_ORG_ID: z.string().optional(),
DEPOT_REGION: z.string().default("us-east-1"),
CONTAINER_REGISTRY_ORIGIN: z.string().optional(),
CONTAINER_REGISTRY_USERNAME: z.string().optional(),
CONTAINER_REGISTRY_PASSWORD: z.string().optional(),
Expand Down
42 changes: 39 additions & 3 deletions apps/webapp/app/v3/remoteImageBuilder.server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { depot } from "@depot/sdk-node";
import { Project } from "@trigger.dev/database";
import { prisma } from "~/db.server";
import { env } from "~/env.server";

export async function createRemoteImageBuild() {
export async function createRemoteImageBuild(project: Project) {
if (!env.DEPOT_TOKEN || !env.DEPOT_PROJECT_ID) {
return;
}

const builderProjectId = await createBuilderProjectIfNotExists(project);

const result = await depot.build.v1.BuildService.createBuild(
{ projectId: env.DEPOT_PROJECT_ID },
{ projectId: builderProjectId },
{
headers: {
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
Expand All @@ -16,8 +20,40 @@ export async function createRemoteImageBuild() {
);

return {
projectId: env.DEPOT_PROJECT_ID,
projectId: builderProjectId,
buildToken: result.buildToken,
buildId: result.buildId,
};
}

async function createBuilderProjectIfNotExists(project: Project) {
if (project.builderProjectId) {
return project.builderProjectId;
}

const result = await depot.core.v1.ProjectService.createProject(
{
name: `${env.APP_ENV} ${project.externalRef}`,
organizationId: env.DEPOT_ORG_ID,
regionId: env.DEPOT_REGION,
},
{
headers: {
Authorization: `Bearer ${env.DEPOT_TOKEN}`,
},
}
);

if (!result.project) {
throw new Error("Failed to create builder project");
}

await prisma.project.update({
where: { id: project.id },
data: {
builderProjectId: result.project.projectId,
},
});

return result.project.projectId;
}
2 changes: 1 addition & 1 deletion apps/webapp/app/v3/services/initializeDeployment.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class InitializeDeploymentService extends BaseService {
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);

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

const triggeredBy = payload.userId
? await this._prisma.user.findUnique({
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@codemirror/view": "^6.5.0",
"@conform-to/react": "^0.6.1",
"@conform-to/zod": "^0.6.1",
"@depot/sdk-node": "^0.5.0",
"@depot/sdk-node": "^1.0.0",
"@headlessui/react": "^1.7.8",
"@heroicons/react": "^2.0.12",
"@internationalized/date": "^3.5.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Project" ADD COLUMN "builderProjectId" TEXT;
2 changes: 2 additions & 0 deletions packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ model Project {

version ProjectVersion @default(V2)

builderProjectId String?

environments RuntimeEnvironment[]
endpoints Endpoint[]
jobs Job[]
Expand Down
37 changes: 19 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading