Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/dokploy/pages/api/deploy/[refreshToken].ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
shouldDeploy,
} from "@dokploy/server";
import { eq } from "drizzle-orm";
import { nanoid } from "nanoid";
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "@/server/db";
import { applications } from "@/server/db/schema";
Expand Down Expand Up @@ -231,13 +232,15 @@ export default async function handler(
}

try {
const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: application.applicationId as string,
titleLog: deploymentTitle,
...(deploymentHash && { descriptionLog: `Hash: ${deploymentHash}` }),
type: "deploy",
applicationType: "application",
server: !!application.serverId,
jobId,
};

if (IS_CLOUD && application.serverId) {
Expand Down
3 changes: 3 additions & 0 deletions apps/dokploy/pages/api/deploy/compose/[refreshToken].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IS_CLOUD, shouldDeploy } from "@dokploy/server";
import { eq } from "drizzle-orm";
import { nanoid } from "nanoid";
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "@/server/db";
import { compose } from "@/server/db/schema";
Expand Down Expand Up @@ -168,13 +169,15 @@ export default async function handler(
}

try {
const jobId = nanoid();
const jobData: DeploymentJob = {
composeId: composeResult.composeId as string,
titleLog: deploymentTitle,
type: "deploy",
applicationType: "compose",
descriptionLog: `Hash: ${deploymentHash}`,
server: !!composeResult.serverId,
jobId,
};

if (IS_CLOUD && composeResult.serverId) {
Expand Down
11 changes: 11 additions & 0 deletions apps/dokploy/pages/api/deploy/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "@dokploy/server";
import { Webhooks } from "@octokit/webhooks";
import { and, eq } from "drizzle-orm";
import { nanoid } from "nanoid";
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "@/server/db";
import { applications, compose, github } from "@/server/db/schema";
Expand Down Expand Up @@ -117,13 +118,15 @@ export default async function handler(
});

for (const app of apps) {
const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: app.applicationId as string,
titleLog: deploymentTitle,
descriptionLog: `Hash: ${deploymentHash}`,
type: "deploy",
applicationType: "application",
server: !!app.serverId,
jobId,
};

if (IS_CLOUD && app.serverId) {
Expand Down Expand Up @@ -156,13 +159,15 @@ export default async function handler(
});

for (const composeApp of composeApps) {
const jobId = nanoid();
const jobData: DeploymentJob = {
composeId: composeApp.composeId as string,
titleLog: deploymentTitle,
type: "deploy",
applicationType: "compose",
descriptionLog: `Hash: ${deploymentHash}`,
server: !!composeApp.serverId,
jobId,
};

if (IS_CLOUD && composeApp.serverId) {
Expand Down Expand Up @@ -230,13 +235,15 @@ export default async function handler(
});

for (const app of apps) {
const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: app.applicationId as string,
titleLog: deploymentTitle,
descriptionLog: `Hash: ${deploymentHash}`,
type: "deploy",
applicationType: "application",
server: !!app.serverId,
jobId,
};

const shouldDeployPaths = shouldDeploy(
Expand Down Expand Up @@ -278,13 +285,15 @@ export default async function handler(
});

for (const composeApp of composeApps) {
const jobId = nanoid();
const jobData: DeploymentJob = {
composeId: composeApp.composeId as string,
titleLog: deploymentTitle,
type: "deploy",
applicationType: "compose",
descriptionLog: `Hash: ${deploymentHash}`,
server: !!composeApp.serverId,
jobId,
};

const shouldDeployPaths = shouldDeploy(
Expand Down Expand Up @@ -487,6 +496,7 @@ export default async function handler(
previewDeploymentId = previewDeployment.previewDeploymentId;
}

const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: app.applicationId as string,
titleLog: "Preview Deployment",
Expand All @@ -495,6 +505,7 @@ export default async function handler(
applicationType: "application-preview",
server: !!app.serverId,
previewDeploymentId,
jobId,
};

if (IS_CLOUD && app.serverId) {
Expand Down
10 changes: 8 additions & 2 deletions apps/dokploy/server/api/routers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,23 @@ export const applicationRouter = createTRPCRouter({
message: "You are not authorized to redeploy this application",
});
}
const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: input.applicationId,
titleLog: input.title || "Rebuild deployment",
descriptionLog: input.description || "",
type: "redeploy",
applicationType: "application",
server: !!application.serverId,
jobId,
};

if (IS_CLOUD && application.serverId) {
jobData.serverId = application.serverId;
deploy(jobData).catch((error) => {
console.error("Background deployment failed:", error);
});
return true;
return { jobId };
}
await myQueue.add(
"deployments",
Expand All @@ -349,6 +351,7 @@ export const applicationRouter = createTRPCRouter({
removeOnFail: true,
},
);
return { jobId };
}),
saveEnvironment: protectedProcedure
.input(apiSaveEnvironmentVariables)
Expand Down Expand Up @@ -693,21 +696,23 @@ export const applicationRouter = createTRPCRouter({
message: "You are not authorized to deploy this application",
});
}
const jobId = nanoid();
const jobData: DeploymentJob = {
applicationId: input.applicationId,
titleLog: input.title || "Manual deployment",
descriptionLog: input.description || "",
type: "deploy",
applicationType: "application",
server: !!application.serverId,
jobId,
};
if (IS_CLOUD && application.serverId) {
jobData.serverId = application.serverId;
deploy(jobData).catch((error) => {
console.error("Background deployment failed:", error);
});

return true;
return { jobId };
}
await myQueue.add(
"deployments",
Expand All @@ -717,6 +722,7 @@ export const applicationRouter = createTRPCRouter({
removeOnFail: true,
},
);
return { jobId };
}),

cleanQueues: protectedProcedure
Expand Down
12 changes: 8 additions & 4 deletions apps/dokploy/server/api/routers/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,23 @@ export const composeRouter = createTRPCRouter({
message: "You are not authorized to deploy this compose",
});
}
const jobId = nanoid();
const jobData: DeploymentJob = {
composeId: input.composeId,
titleLog: input.title || "Manual deployment",
type: "deploy",
applicationType: "compose",
descriptionLog: input.description || "",
server: !!compose.serverId,
jobId,
};

if (IS_CLOUD && compose.serverId) {
jobData.serverId = compose.serverId;
deploy(jobData).catch((error) => {
console.error("Background deployment failed:", error);
});
return true;
return { jobId };
}
await myQueue.add(
"deployments",
Expand All @@ -430,7 +432,7 @@ export const composeRouter = createTRPCRouter({
removeOnFail: true,
},
);
return { success: true, message: "Deployment queued" };
return { jobId };
}),
redeploy: protectedProcedure
.input(apiRedeployCompose)
Expand All @@ -445,20 +447,22 @@ export const composeRouter = createTRPCRouter({
message: "You are not authorized to redeploy this compose",
});
}
const jobId = nanoid();
const jobData: DeploymentJob = {
composeId: input.composeId,
titleLog: input.title || "Rebuild deployment",
type: "redeploy",
applicationType: "compose",
descriptionLog: input.description || "",
server: !!compose.serverId,
jobId,
};
if (IS_CLOUD && compose.serverId) {
jobData.serverId = compose.serverId;
deploy(jobData).catch((error) => {
console.error("Background deployment failed:", error);
});
return true;
return { jobId };
}
await myQueue.add(
"deployments",
Expand All @@ -468,7 +472,7 @@ export const composeRouter = createTRPCRouter({
removeOnFail: true,
},
);
return { success: true, message: "Redeployment queued" };
return { jobId };
}),
stop: protectedProcedure
.input(apiFindCompose)
Expand Down
5 changes: 5 additions & 0 deletions apps/dokploy/server/queues/deployments-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export const deploymentWorker = new Worker(
applicationId: job.data.applicationId,
titleLog: job.data.titleLog,
descriptionLog: job.data.descriptionLog,
jobId: job.data.jobId,
});
} else if (job.data.type === "deploy") {
await deployApplication({
applicationId: job.data.applicationId,
titleLog: job.data.titleLog,
descriptionLog: job.data.descriptionLog,
jobId: job.data.jobId,
});
}
} else if (job.data.applicationType === "compose") {
Expand All @@ -41,12 +43,14 @@ export const deploymentWorker = new Worker(
composeId: job.data.composeId,
titleLog: job.data.titleLog,
descriptionLog: job.data.descriptionLog,
jobId: job.data.jobId,
});
} else if (job.data.type === "redeploy") {
await rebuildCompose({
composeId: job.data.composeId,
titleLog: job.data.titleLog,
descriptionLog: job.data.descriptionLog,
jobId: job.data.jobId,
});
}
} else if (job.data.applicationType === "application-preview") {
Expand All @@ -60,6 +64,7 @@ export const deploymentWorker = new Worker(
titleLog: job.data.titleLog,
descriptionLog: job.data.descriptionLog,
previewDeploymentId: job.data.previewDeploymentId,
jobId: job.data.jobId,
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions apps/dokploy/server/queues/queue-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type DeployJob =
type: "deploy" | "redeploy";
applicationType: "application";
serverId?: string;
jobId?: string;
}
| {
composeId: string;
Expand All @@ -16,6 +17,7 @@ type DeployJob =
type: "deploy" | "redeploy";
applicationType: "compose";
serverId?: string;
jobId?: string;
}
| {
applicationId: string;
Expand All @@ -26,6 +28,7 @@ type DeployJob =
applicationType: "application-preview";
previewDeploymentId: string;
serverId?: string;
jobId?: string;
};

export type DeploymentJob = DeployJob;
9 changes: 9 additions & 0 deletions packages/server/src/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ export const deployApplication = async ({
applicationId,
titleLog = "Manual deployment",
descriptionLog = "",
jobId,
}: {
applicationId: string;
titleLog: string;
descriptionLog: string;
jobId?: string;
}) => {
const application = await findApplicationById(applicationId);
const serverId = application.buildServerId || application.serverId;
Expand All @@ -180,6 +182,7 @@ export const deployApplication = async ({
applicationId: applicationId,
title: titleLog,
description: descriptionLog,
jobId,
});

try {
Expand Down Expand Up @@ -270,10 +273,12 @@ export const rebuildApplication = async ({
applicationId,
titleLog = "Rebuild deployment",
descriptionLog = "",
jobId,
}: {
applicationId: string;
titleLog: string;
descriptionLog: string;
jobId?: string;
}) => {
const application = await findApplicationById(applicationId);
const serverId = application.buildServerId || application.serverId;
Expand All @@ -283,6 +288,7 @@ export const rebuildApplication = async ({
applicationId: applicationId,
title: titleLog,
description: descriptionLog,
jobId,
});

try {
Expand Down Expand Up @@ -337,18 +343,21 @@ export const deployPreviewApplication = async ({
titleLog = "Preview Deployment",
descriptionLog = "",
previewDeploymentId,
jobId,
}: {
applicationId: string;
titleLog: string;
descriptionLog: string;
previewDeploymentId: string;
jobId?: string;
}) => {
const application = await findApplicationById(applicationId);

const deployment = await createDeploymentPreview({
title: titleLog,
description: descriptionLog,
previewDeploymentId: previewDeploymentId,
jobId,
});

const previewDeployment =
Expand Down
Loading