diff --git a/components/dashboard/application/deployments/show-deployments.tsx b/components/dashboard/application/deployments/show-deployments.tsx
index f70808a1..ff26dc84 100644
--- a/components/dashboard/application/deployments/show-deployments.tsx
+++ b/components/dashboard/application/deployments/show-deployments.tsx
@@ -86,6 +86,11 @@ export const ShowDeployments = ({ applicationId }: Props) => {
{deployment.title}
+ {deployment.description && (
+
+ {deployment.description}
+
+ )}
diff --git a/pages/api/deploy/[refreshToken].ts b/pages/api/deploy/[refreshToken].ts
index 1e632664..c2aa3f16 100644
--- a/pages/api/deploy/[refreshToken].ts
+++ b/pages/api/deploy/[refreshToken].ts
@@ -33,6 +33,7 @@ export default async function handler(
}
const deploymentTitle = extractCommitMessage(req.headers, req.body);
+ const deploymentHash = extractHash(req.headers, req.body);
const sourceType = application.sourceType;
@@ -75,6 +76,7 @@ export default async function handler(
const jobData: DeploymentJob = {
applicationId: application.applicationId as string,
titleLog: deploymentTitle,
+ descriptionLog: `Hash: ${deploymentHash}`,
type: "deploy",
applicationType: "application",
};
@@ -166,6 +168,37 @@ export const extractCommitMessage = (headers: any, body: any) => {
return "NEW CHANGES";
};
+export const extractHash = (headers: any, body: any) => {
+ // GitHub
+ if (headers["x-github-event"]) {
+ return body.head_commit ? body.head_commit.id : "";
+ }
+
+ // GitLab
+ if (headers["x-gitlab-event"]) {
+ return (
+ body.checkout_sha ||
+ (body.commits && body.commits.length > 0
+ ? body.commits[0].id
+ : "NEW COMMIT")
+ );
+ }
+
+ // Bitbucket
+ if (headers["x-event-key"]?.includes("repo:push")) {
+ return body.push.changes && body.push.changes.length > 0
+ ? body.push.changes[0].new.target.hash
+ : "NEW COMMIT";
+ }
+
+ // Gitea
+ if (headers["x-gitea-event"]) {
+ return body.after || "NEW COMMIT";
+ }
+
+ return "";
+};
+
export const extractBranchName = (headers: any, body: any) => {
if (headers["x-github-event"] || headers["x-gitea-event"]) {
return body?.ref?.replace("refs/heads/", "");
diff --git a/pages/api/deploy/compose/[refreshToken].ts b/pages/api/deploy/compose/[refreshToken].ts
index 4f9b121b..1c573981 100644
--- a/pages/api/deploy/compose/[refreshToken].ts
+++ b/pages/api/deploy/compose/[refreshToken].ts
@@ -4,7 +4,11 @@ import type { DeploymentJob } from "@/server/queues/deployments-queue";
import { myQueue } from "@/server/queues/queueSetup";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
-import { extractBranchName, extractCommitMessage } from "../[refreshToken]";
+import {
+ extractBranchName,
+ extractCommitMessage,
+ extractHash,
+} from "../[refreshToken]";
import { updateCompose } from "@/server/api/services/compose";
export default async function handler(
@@ -34,7 +38,7 @@ export default async function handler(
}
const deploymentTitle = extractCommitMessage(req.headers, req.body);
-
+ const deploymentHash = extractHash(req.headers, req.body);
const sourceType = composeResult.sourceType;
if (sourceType === "github") {
@@ -61,6 +65,7 @@ export default async function handler(
titleLog: deploymentTitle,
type: "deploy",
applicationType: "compose",
+ descriptionLog: `Hash: ${deploymentHash}`,
};
await myQueue.add(
"deployments",
diff --git a/server/api/routers/application.ts b/server/api/routers/application.ts
index df5f2b50..77b8befe 100644
--- a/server/api/routers/application.ts
+++ b/server/api/routers/application.ts
@@ -162,6 +162,7 @@ export const applicationRouter = createTRPCRouter({
const jobData: DeploymentJob = {
applicationId: input.applicationId,
titleLog: "Rebuild deployment",
+ descriptionLog: "",
type: "redeploy",
applicationType: "application",
};
@@ -294,6 +295,7 @@ export const applicationRouter = createTRPCRouter({
const jobData: DeploymentJob = {
applicationId: input.applicationId,
titleLog: "Manual deployment",
+ descriptionLog: "",
type: "deploy",
applicationType: "application",
};
diff --git a/server/api/services/application.ts b/server/api/services/application.ts
index e5719a9a..b093f63f 100644
--- a/server/api/services/application.ts
+++ b/server/api/services/application.ts
@@ -130,15 +130,18 @@ export const updateApplicationStatus = async (
export const deployApplication = async ({
applicationId,
titleLog = "Manual deployment",
+ descriptionLog = "",
}: {
applicationId: string;
titleLog: string;
+ descriptionLog: string;
}) => {
const application = await findApplicationById(applicationId);
const admin = await findAdmin();
const deployment = await createDeployment({
applicationId: applicationId,
title: titleLog,
+ description: descriptionLog,
});
try {
@@ -173,14 +176,17 @@ export const deployApplication = async ({
export const rebuildApplication = async ({
applicationId,
titleLog = "Rebuild deployment",
+ descriptionLog = "",
}: {
applicationId: string;
titleLog: string;
+ descriptionLog: string;
}) => {
const application = await findApplicationById(applicationId);
const deployment = await createDeployment({
applicationId: applicationId,
title: titleLog,
+ description: descriptionLog,
});
try {
diff --git a/server/api/services/compose.ts b/server/api/services/compose.ts
index 63065e6c..97d27e7e 100644
--- a/server/api/services/compose.ts
+++ b/server/api/services/compose.ts
@@ -134,15 +134,18 @@ export const updateCompose = async (
export const deployCompose = async ({
composeId,
titleLog = "Manual deployment",
+ descriptionLog = "",
}: {
composeId: string;
titleLog: string;
+ descriptionLog: string;
}) => {
const compose = await findComposeById(composeId);
const admin = await findAdmin();
const deployment = await createDeploymentCompose({
composeId: composeId,
title: titleLog,
+ description: descriptionLog,
});
try {
@@ -170,14 +173,17 @@ export const deployCompose = async ({
export const rebuildCompose = async ({
composeId,
titleLog = "Rebuild deployment",
+ descriptionLog = "",
}: {
composeId: string;
titleLog: string;
+ descriptionLog: string;
}) => {
const compose = await findComposeById(composeId);
const deployment = await createDeploymentCompose({
composeId: composeId,
title: titleLog,
+ description: descriptionLog,
});
try {
diff --git a/server/api/services/deployment.ts b/server/api/services/deployment.ts
index b946fa7a..e3bbad79 100644
--- a/server/api/services/deployment.ts
+++ b/server/api/services/deployment.ts
@@ -60,6 +60,7 @@ export const createDeployment = async (
title: deployment.title || "Deployment",
status: "running",
logPath: logFilePath,
+ description: deployment.description || "",
})
.returning();
if (deploymentCreate.length === 0 || !deploymentCreate[0]) {
@@ -100,6 +101,7 @@ export const createDeploymentCompose = async (
.values({
composeId: deployment.composeId,
title: deployment.title || "Deployment",
+ description: deployment.description || "",
status: "running",
logPath: logFilePath,
})
diff --git a/server/db/schema/deployment.ts b/server/db/schema/deployment.ts
index eaadc695..58931d6d 100644
--- a/server/db/schema/deployment.ts
+++ b/server/db/schema/deployment.ts
@@ -18,6 +18,7 @@ export const deployments = pgTable("deployment", {
.primaryKey()
.$defaultFn(() => nanoid()),
title: text("title").notNull(),
+ description: text("description"),
status: deploymentStatus("status").default("running"),
logPath: text("logPath").notNull(),
applicationId: text("applicationId").references(
@@ -49,6 +50,7 @@ const schema = createInsertSchema(deployments, {
logPath: z.string().min(1),
applicationId: z.string(),
composeId: z.string(),
+ description: z.string().optional(),
});
export const apiCreateDeployment = schema
@@ -57,6 +59,7 @@ export const apiCreateDeployment = schema
status: true,
logPath: true,
applicationId: true,
+ description: true,
})
.extend({
applicationId: z.string().min(1),
@@ -68,6 +71,7 @@ export const apiCreateDeploymentCompose = schema
status: true,
logPath: true,
composeId: true,
+ description: true,
})
.extend({
composeId: z.string().min(1),
diff --git a/server/queues/deployments-queue.ts b/server/queues/deployments-queue.ts
index ef909d8e..54f23073 100644
--- a/server/queues/deployments-queue.ts
+++ b/server/queues/deployments-queue.ts
@@ -10,12 +10,14 @@ type DeployJob =
| {
applicationId: string;
titleLog: string;
+ descriptionLog: string;
type: "deploy" | "redeploy";
applicationType: "application";
}
| {
composeId: string;
titleLog: string;
+ descriptionLog: string;
type: "deploy" | "redeploy";
applicationType: "compose";
};
@@ -31,11 +33,13 @@ export const deploymentWorker = new Worker(
await rebuildApplication({
applicationId: job.data.applicationId,
titleLog: job.data.titleLog,
+ descriptionLog: job.data.descriptionLog,
});
} else if (job.data.type === "deploy") {
await deployApplication({
applicationId: job.data.applicationId,
titleLog: job.data.titleLog,
+ descriptionLog: job.data.descriptionLog,
});
}
} else if (job.data.applicationType === "compose") {
@@ -43,11 +47,13 @@ export const deploymentWorker = new Worker(
await deployCompose({
composeId: job.data.composeId,
titleLog: job.data.titleLog,
+ descriptionLog: job.data.descriptionLog,
});
} else if (job.data.type === "redeploy") {
await rebuildCompose({
composeId: job.data.composeId,
titleLog: job.data.titleLog,
+ descriptionLog: job.data.descriptionLog,
});
}
}