refactor(cloud): add deploy to external API

This commit is contained in:
Mauricio Siu
2024-10-04 18:53:46 -06:00
parent 3df2f8e58c
commit 5cebf5540a
10 changed files with 92 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import { findAdmin } from "@dokploy/builders";
import { findAdmin, IS_CLOUD } from "@dokploy/builders";
import { db } from "@/server/db";
import { applications, compose, github } from "@/server/db/schema";
import type { DeploymentJob } from "@/server/queues/deployments-queue";
@@ -7,6 +7,7 @@ import { Webhooks } from "@octokit/webhooks";
import { and, eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { extractCommitMessage, extractHash } from "./[refreshToken]";
import { deploy } from "@/server/utils/deploy";
export default async function handler(
req: NextApiRequest,
@@ -88,6 +89,12 @@ export default async function handler(
applicationType: "application",
server: !!app.serverId,
};
if (IS_CLOUD && app.serverId) {
jobData.serverId = app.serverId;
await deploy(jobData);
return true;
}
await myQueue.add(
"deployments",
{ ...jobData },
@@ -116,6 +123,12 @@ export default async function handler(
descriptionLog: `Hash: ${deploymentHash}`,
};
if (IS_CLOUD && composeApp.serverId) {
jobData.serverId = composeApp.serverId;
await deploy(jobData);
return true;
}
await myQueue.add(
"deployments",
{ ...jobData },