diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index a76b60032..fcac429ca 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -5,7 +5,7 @@ import { zValidator } from "@hono/zod-validator"; import { Inngest } from "inngest"; import { serve as serveInngest } from "inngest/hono"; import { logger } from "./logger.js"; -import { type DeployJob, deployJobSchema, deployRequestSchema } from "./schema.js"; +import { type DeployJob, deployJobSchema } from "./schema.js"; import { deploy } from "./utils.js"; const app = new Hono(); @@ -84,22 +84,15 @@ app.use(async (c, next) => { return next(); }); -app.post("/deploy", zValidator("json", deployRequestSchema), async (c) => { +app.post("/deploy", zValidator("json", deployJobSchema), async (c) => { const data = c.req.valid("json"); logger.info("Received deployment request", data); try { - // Transform the request to the internal job format - const jobData: DeployJob = { - ...data, - titleLog: data.title || "Manual deployment", - descriptionLog: data.description || "", - }; - // Send event to Inngest instead of adding to Redis queue await inngest.send({ name: "deployment/requested", - data: jobData, + data, }); logger.info("Deployment event sent to Inngest", { @@ -142,4 +135,4 @@ app.on( const port = Number.parseInt(process.env.PORT || "3000"); logger.info("Starting Deployments Server with Inngest ✅", port); -serve({ fetch: app.fetch, port }); +serve({ fetch: app.fetch, port }); \ No newline at end of file diff --git a/apps/api/src/schema.ts b/apps/api/src/schema.ts index 8097ae1fb..f29b7c6e0 100644 --- a/apps/api/src/schema.ts +++ b/apps/api/src/schema.ts @@ -3,8 +3,8 @@ import { z } from "zod"; export const deployJobSchema = z.discriminatedUnion("applicationType", [ z.object({ applicationId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy", "redeploy"]), applicationType: z.literal("application"), @@ -12,8 +12,8 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ }), z.object({ composeId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy", "redeploy"]), applicationType: z.literal("compose"), @@ -22,8 +22,8 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ z.object({ applicationId: z.string(), previewDeploymentId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy"]), applicationType: z.literal("application-preview"), @@ -31,35 +31,5 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ }), ]); -export const deployRequestSchema = z.discriminatedUnion("applicationType", [ - z.object({ - applicationId: z.string(), - title: z.string().optional(), - description: z.string().optional(), - server: z.boolean().optional(), - type: z.enum(["deploy", "redeploy"]), - applicationType: z.literal("application"), - serverId: z.string().min(1), - }), - z.object({ - composeId: z.string(), - title: z.string().optional(), - description: z.string().optional(), - server: z.boolean().optional(), - type: z.enum(["deploy", "redeploy"]), - applicationType: z.literal("compose"), - serverId: z.string().min(1), - }), - z.object({ - applicationId: z.string(), - previewDeploymentId: z.string(), - title: z.string().optional(), - description: z.string().optional(), - server: z.boolean().optional(), - type: z.enum(["deploy"]), - applicationType: z.literal("application-preview"), - serverId: z.string().min(1), - }), -]); export type DeployJob = z.infer; diff --git a/apps/api/src/utils.ts b/apps/api/src/utils.ts index ee3943d34..ee2ac3e50 100644 --- a/apps/api/src/utils.ts +++ b/apps/api/src/utils.ts @@ -18,14 +18,14 @@ export const deploy = async (job: DeployJob) => { if (job.type === "redeploy") { await rebuildRemoteApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Rebuild deployment", + descriptionLog: job.descriptionLog || "", }); } else if (job.type === "deploy") { await deployRemoteApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Manual deployment", + descriptionLog: job.descriptionLog || "", }); } } @@ -38,14 +38,14 @@ export const deploy = async (job: DeployJob) => { if (job.type === "redeploy") { await rebuildRemoteCompose({ composeId: job.composeId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Rebuild deployment", + descriptionLog: job.descriptionLog || "", }); } else if (job.type === "deploy") { await deployRemoteCompose({ composeId: job.composeId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Manual deployment", + descriptionLog: job.descriptionLog || "", }); } } @@ -57,8 +57,8 @@ export const deploy = async (job: DeployJob) => { if (job.type === "deploy") { await deployRemotePreviewApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Preview Deployment", + descriptionLog: job.descriptionLog || "", previewDeploymentId: job.previewDeploymentId, }); }