Skip to content

Commit 3cc7874

Browse files
committed
fix(webapp): add template creation to V1 finalize path (non-remote builds)
1 parent 899a7fb commit 3cc7874

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { TimeoutDeploymentService } from "./timeoutDeployment.server";
1212
import { DeploymentService } from "./deployment.server";
1313
import { engine } from "../runEngine.server";
1414
import { tryCatch } from "@trigger.dev/core";
15+
import { ComputeTemplateCreationService } from "./computeTemplateCreation.server";
1516

1617
export class FinalizeDeploymentService extends BaseService {
1718
public async call(
@@ -65,6 +66,47 @@ export class FinalizeDeploymentService extends BaseService {
6566

6667
const imageDigest = validatedImageDigest(body.imageDigest);
6768

69+
// Compute template creation (before setting DEPLOYED)
70+
const templateService = new ComputeTemplateCreationService();
71+
const templateMode = await templateService.resolveMode(
72+
authenticatedEnv.projectId,
73+
this._prisma
74+
);
75+
76+
if (templateMode === "required" && deployment.imageReference) {
77+
logger.info("Creating compute template (required mode)", {
78+
id,
79+
imageReference: deployment.imageReference,
80+
});
81+
82+
const templateResult = await templateService.createTemplate(deployment.imageReference);
83+
84+
if (!templateResult.success) {
85+
logger.error("Compute template creation failed", {
86+
id,
87+
imageReference: deployment.imageReference,
88+
error: templateResult.error,
89+
});
90+
91+
const failService = new FailDeploymentService();
92+
await failService.call(authenticatedEnv, deployment.friendlyId, {
93+
error: {
94+
name: "TemplateCreationFailed",
95+
message: `Failed to create compute template: ${templateResult.error}`,
96+
},
97+
});
98+
99+
throw new ServiceValidationError(
100+
`Compute template creation failed: ${templateResult.error}`
101+
);
102+
}
103+
104+
logger.info("Compute template created", {
105+
id,
106+
imageReference: deployment.imageReference,
107+
});
108+
}
109+
68110
// Link the deployment with the background worker
69111
const finalizedDeployment = await this._prisma.workerDeployment.update({
70112
where: {
@@ -147,6 +189,17 @@ export class FinalizeDeploymentService extends BaseService {
147189

148190
await PerformDeploymentAlertsService.enqueue(deployment.id);
149191

192+
// Shadow mode: fire-and-forget template creation after deploy is finalized
193+
if (templateMode === "shadow" && deployment.imageReference) {
194+
templateService.createTemplate(deployment.imageReference).catch((error) => {
195+
logger.error("Shadow compute template creation failed", {
196+
id,
197+
imageReference: deployment.imageReference,
198+
error: error instanceof Error ? error.message : String(error),
199+
});
200+
});
201+
}
202+
150203
return finalizedDeployment;
151204
}
152205
}

0 commit comments

Comments
 (0)