Skip to content

Commit 276f1f7

Browse files
1stvampTrigger.dev RepoOps
authored andcommitted
feat(webapp): select admin template builds by org, project and environment
Admin template builds can now select deployments by organisation, project and environment type, accept deployment short codes, and wait for slow builds to finish, streaming each result as it completes. Mono-RevId: 3ba72ec11729b3504ea4023252fcc03f20fb0968
1 parent e7ebad1 commit 276f1f7

8 files changed

Lines changed: 931 additions & 51 deletions

‎apps/webapp/app/env.server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,8 @@ const EnvironmentSchema = z
943943
TEMPLATE_BUILDER_TOKEN: z.string().optional(),
944944
// How long wait mode holds finalisation for the builder before carrying on.
945945
TEMPLATE_BUILDER_TIMEOUT_MS: z.coerce.number().int().positive().default(60_000),
946+
// How long the admin template-builds route waits on each build when `wait` is set.
947+
TEMPLATE_BUILDER_ADMIN_TIMEOUT_MS: z.coerce.number().int().positive().default(900_000),
946948
// Machine presets whose shapes are sent with the template request.
947949
TEMPLATE_BUILDER_MACHINE_PRESETS: z
948950
.string()

‎apps/webapp/app/routes/admin.api.v1.deployments.template-builds.ts‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import { withAdminAudit } from "~/services/adminAudit/adminAudit.server";
22
import type { ActionFunctionArgs } from "@remix-run/server-runtime";
33
import { json } from "@remix-run/server-runtime";
44
import { tryCatch } from "@trigger.dev/core/v3";
5-
import { z } from "zod";
6-
import { logger } from "~/services/logger.server";
75
import { requireAdminApiRequest } from "~/services/personalAccessToken.server";
8-
import { TemplatePrebuildService } from "~/v3/services/templatePrebuild.server";
9-
10-
const BodySchema = z.object({
11-
// Deployment ids or friendly ids.
12-
deploymentIds: z.array(z.string().min(1)).min(1).max(50),
13-
force: z.boolean().default(false),
14-
});
6+
import {
7+
adminTemplateBuilds,
8+
TemplateBuildsBodySchema,
9+
} from "~/v3/services/adminTemplateBuilds.server";
1510

1611
async function handleAction({ request }: ActionFunctionArgs) {
1712
await requireAdminApiRequest(request);
@@ -25,24 +20,12 @@ async function handleAction({ request }: ActionFunctionArgs) {
2520
return json({ error: bodyError.message }, { status: 400 });
2621
}
2722

28-
const parsedBody = BodySchema.safeParse(body);
23+
const parsedBody = TemplateBuildsBodySchema.safeParse(body);
2924
if (!parsedBody.success) {
3025
return json({ error: parsedBody.error.message }, { status: 400 });
3126
}
3227

33-
const deploymentIds = [...new Set(parsedBody.data.deploymentIds)];
34-
const results = await new TemplatePrebuildService().requestBuilds({
35-
deploymentIds,
36-
force: parsedBody.data.force,
37-
});
38-
39-
logger.info("Admin template builds requested", {
40-
count: deploymentIds.length,
41-
force: parsedBody.data.force,
42-
results,
43-
});
44-
45-
return json({ results });
28+
return adminTemplateBuilds(parsedBody.data);
4629
}
4730

4831
export const action = withAdminAudit(handleAction);

0 commit comments

Comments
 (0)