mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-09 13:35:19 +00:00
feat: add custom title/description support for API/CLI deployments - Add optional title and description fields to deployment schemas - Update TRPC endpoints to accept custom deployment titles/descriptions - Update external API to support custom deployment metadata - Maintain backward compatibility with existing deployments - Resolves issue #1485: Allow setting title/description for deployments via API/CLI
This commit is contained in:
+10
-3
@@ -5,7 +5,7 @@ import { zValidator } from "@hono/zod-validator";
|
|||||||
import { Inngest } from "inngest";
|
import { Inngest } from "inngest";
|
||||||
import { serve as serveInngest } from "inngest/hono";
|
import { serve as serveInngest } from "inngest/hono";
|
||||||
import { logger } from "./logger.js";
|
import { logger } from "./logger.js";
|
||||||
import { type DeployJob, deployJobSchema } from "./schema.js";
|
import { type DeployJob, deployJobSchema, deployRequestSchema } from "./schema.js";
|
||||||
import { deploy } from "./utils.js";
|
import { deploy } from "./utils.js";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
@@ -84,15 +84,22 @@ app.use(async (c, next) => {
|
|||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/deploy", zValidator("json", deployJobSchema), async (c) => {
|
app.post("/deploy", zValidator("json", deployRequestSchema), async (c) => {
|
||||||
const data = c.req.valid("json");
|
const data = c.req.valid("json");
|
||||||
logger.info("Received deployment request", data);
|
logger.info("Received deployment request", data);
|
||||||
|
|
||||||
try {
|
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
|
// Send event to Inngest instead of adding to Redis queue
|
||||||
await inngest.send({
|
await inngest.send({
|
||||||
name: "deployment/requested",
|
name: "deployment/requested",
|
||||||
data,
|
data: jobData,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info("Deployment event sent to Inngest", {
|
logger.info("Deployment event sent to Inngest", {
|
||||||
|
|||||||
@@ -31,4 +31,35 @@ 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<typeof deployJobSchema>;
|
export type DeployJob = z.infer<typeof deployJobSchema>;
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ import {
|
|||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import {
|
import {
|
||||||
apiCreateApplication,
|
apiCreateApplication,
|
||||||
|
apiDeployApplication,
|
||||||
apiFindMonitoringStats,
|
apiFindMonitoringStats,
|
||||||
apiFindOneApplication,
|
apiFindOneApplication,
|
||||||
|
apiRedeployApplication,
|
||||||
apiReloadApplication,
|
apiReloadApplication,
|
||||||
apiSaveBitbucketProvider,
|
apiSaveBitbucketProvider,
|
||||||
apiSaveBuildType,
|
apiSaveBuildType,
|
||||||
@@ -292,7 +294,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
redeploy: protectedProcedure
|
redeploy: protectedProcedure
|
||||||
.input(apiFindOneApplication)
|
.input(apiRedeployApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (
|
if (
|
||||||
@@ -305,8 +307,8 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const jobData: DeploymentJob = {
|
const jobData: DeploymentJob = {
|
||||||
applicationId: input.applicationId,
|
applicationId: input.applicationId,
|
||||||
titleLog: "Rebuild deployment",
|
titleLog: input.title || "Rebuild deployment",
|
||||||
descriptionLog: "",
|
descriptionLog: input.description || "",
|
||||||
type: "redeploy",
|
type: "redeploy",
|
||||||
applicationType: "application",
|
applicationType: "application",
|
||||||
server: !!application.serverId,
|
server: !!application.serverId,
|
||||||
@@ -643,7 +645,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
deploy: protectedProcedure
|
deploy: protectedProcedure
|
||||||
.input(apiFindOneApplication)
|
.input(apiDeployApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const application = await findApplicationById(input.applicationId);
|
const application = await findApplicationById(input.applicationId);
|
||||||
if (
|
if (
|
||||||
@@ -656,8 +658,8 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const jobData: DeploymentJob = {
|
const jobData: DeploymentJob = {
|
||||||
applicationId: input.applicationId,
|
applicationId: input.applicationId,
|
||||||
titleLog: "Manual deployment",
|
titleLog: input.title || "Manual deployment",
|
||||||
descriptionLog: "",
|
descriptionLog: input.description || "",
|
||||||
type: "deploy",
|
type: "deploy",
|
||||||
applicationType: "application",
|
applicationType: "application",
|
||||||
server: !!application.serverId,
|
server: !!application.serverId,
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ import { db } from "@/server/db";
|
|||||||
import {
|
import {
|
||||||
apiCreateCompose,
|
apiCreateCompose,
|
||||||
apiDeleteCompose,
|
apiDeleteCompose,
|
||||||
|
apiDeployCompose,
|
||||||
apiFetchServices,
|
apiFetchServices,
|
||||||
apiFindCompose,
|
apiFindCompose,
|
||||||
apiRandomizeCompose,
|
apiRandomizeCompose,
|
||||||
|
apiRedeployCompose,
|
||||||
apiUpdateCompose,
|
apiUpdateCompose,
|
||||||
compose as composeTable,
|
compose as composeTable,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
@@ -337,7 +339,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deploy: protectedProcedure
|
deploy: protectedProcedure
|
||||||
.input(apiFindCompose)
|
.input(apiDeployCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
|
|
||||||
@@ -349,10 +351,10 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const jobData: DeploymentJob = {
|
const jobData: DeploymentJob = {
|
||||||
composeId: input.composeId,
|
composeId: input.composeId,
|
||||||
titleLog: "Manual deployment",
|
titleLog: input.title || "Manual deployment",
|
||||||
type: "deploy",
|
type: "deploy",
|
||||||
applicationType: "compose",
|
applicationType: "compose",
|
||||||
descriptionLog: "",
|
descriptionLog: input.description || "",
|
||||||
server: !!compose.serverId,
|
server: !!compose.serverId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -371,7 +373,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
redeploy: protectedProcedure
|
redeploy: protectedProcedure
|
||||||
.input(apiFindCompose)
|
.input(apiRedeployCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const compose = await findComposeById(input.composeId);
|
const compose = await findComposeById(input.composeId);
|
||||||
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (compose.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
@@ -382,10 +384,10 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const jobData: DeploymentJob = {
|
const jobData: DeploymentJob = {
|
||||||
composeId: input.composeId,
|
composeId: input.composeId,
|
||||||
titleLog: "Rebuild deployment",
|
titleLog: input.title || "Rebuild deployment",
|
||||||
type: "redeploy",
|
type: "redeploy",
|
||||||
applicationType: "compose",
|
applicationType: "compose",
|
||||||
descriptionLog: "",
|
descriptionLog: input.description || "",
|
||||||
server: !!compose.serverId,
|
server: !!compose.serverId,
|
||||||
};
|
};
|
||||||
if (IS_CLOUD && compose.serverId) {
|
if (IS_CLOUD && compose.serverId) {
|
||||||
|
|||||||
@@ -327,6 +327,26 @@ export const apiFindOneApplication = createSchema
|
|||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
|
||||||
|
export const apiDeployApplication = createSchema
|
||||||
|
.pick({
|
||||||
|
applicationId: true,
|
||||||
|
})
|
||||||
|
.extend({
|
||||||
|
applicationId: z.string().min(1),
|
||||||
|
title: z.string().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const apiRedeployApplication = createSchema
|
||||||
|
.pick({
|
||||||
|
applicationId: true,
|
||||||
|
})
|
||||||
|
.extend({
|
||||||
|
applicationId: z.string().min(1),
|
||||||
|
title: z.string().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
export const apiReloadApplication = createSchema
|
export const apiReloadApplication = createSchema
|
||||||
.pick({
|
.pick({
|
||||||
appName: true,
|
appName: true,
|
||||||
|
|||||||
@@ -180,6 +180,18 @@ export const apiFindCompose = z.object({
|
|||||||
composeId: z.string().min(1),
|
composeId: z.string().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const apiDeployCompose = z.object({
|
||||||
|
composeId: z.string().min(1),
|
||||||
|
title: z.string().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const apiRedeployCompose = z.object({
|
||||||
|
composeId: z.string().min(1),
|
||||||
|
title: z.string().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
export const apiDeleteCompose = z.object({
|
export const apiDeleteCompose = z.object({
|
||||||
composeId: z.string().min(1),
|
composeId: z.string().min(1),
|
||||||
deleteVolumes: z.boolean(),
|
deleteVolumes: z.boolean(),
|
||||||
|
|||||||
Reference in New Issue
Block a user