diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index a0b0ea7d..bcedc370 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -1,6 +1,6 @@ import { db } from "@/server/db"; import { applications } from "@/server/db/schema"; -import type { DeploymentJob } from "@/server/queues/deployments-queue"; +import type { DeploymentJob } from "@/server/queues/queue-types"; import { myQueue } from "@/server/queues/queueSetup"; import { deploy } from "@/server/utils/deploy"; import { IS_CLOUD } from "@dokploy/server"; diff --git a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts index 5ef9c271..14a010f2 100644 --- a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts @@ -1,6 +1,6 @@ import { db } from "@/server/db"; import { compose } from "@/server/db/schema"; -import type { DeploymentJob } from "@/server/queues/deployments-queue"; +import type { DeploymentJob } from "@/server/queues/queue-types"; import { myQueue } from "@/server/queues/queueSetup"; import { deploy } from "@/server/utils/deploy"; import { IS_CLOUD } from "@dokploy/server"; diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 2ffdc078..bdbc0293 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -1,6 +1,6 @@ import { db } from "@/server/db"; import { applications, compose, github } from "@/server/db/schema"; -import type { DeploymentJob } from "@/server/queues/deployments-queue"; +import type { DeploymentJob } from "@/server/queues/queue-types"; import { myQueue } from "@/server/queues/queueSetup"; import { deploy } from "@/server/utils/deploy"; import { IS_CLOUD } from "@dokploy/server"; diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index 270f6ca7..2f006471 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -19,11 +19,8 @@ import { apiUpdateApplication, applications, } from "@/server/db/schema"; -import { - type DeploymentJob, - cleanQueuesByApplication, -} from "@/server/queues/deployments-queue"; -import { myQueue } from "@/server/queues/queueSetup"; +import type { DeploymentJob } from "@/server/queues/queue-types"; +import { cleanQueuesByApplication, myQueue } from "@/server/queues/queueSetup"; import { deploy } from "@/server/utils/deploy"; import { uploadFileSchema } from "@/utils/schema"; import { diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index f50956b2..e9ccd33b 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -9,11 +9,7 @@ import { apiUpdateCompose, compose, } from "@/server/db/schema"; -import { - type DeploymentJob, - cleanQueuesByCompose, -} from "@/server/queues/deployments-queue"; -import { myQueue } from "@/server/queues/queueSetup"; +import { cleanQueuesByCompose, myQueue } from "@/server/queues/queueSetup"; import { templates } from "@/templates/templates"; import type { TemplatesKeys } from "@/templates/types/templates-data.type"; import { @@ -28,6 +24,7 @@ import _ from "lodash"; import { nanoid } from "nanoid"; import { createTRPCRouter, protectedProcedure } from "../trpc"; +import type { DeploymentJob } from "@/server/queues/queue-types"; import { deploy } from "@/server/utils/deploy"; import { IS_CLOUD, @@ -41,7 +38,6 @@ import { createComposeByTemplate, createDomain, createMount, - findAdmin, findAdminById, findComposeById, findDomainsByComposeId, diff --git a/apps/dokploy/server/queues/deployments-queue.ts b/apps/dokploy/server/queues/deployments-queue.ts index 1ef88c3d..08e0c9a1 100644 --- a/apps/dokploy/server/queues/deployments-queue.ts +++ b/apps/dokploy/server/queues/deployments-queue.ts @@ -11,29 +11,8 @@ import { updateCompose, } from "@dokploy/server"; import { type Job, Worker } from "bullmq"; -import { myQueue, redisConfig } from "./queueSetup"; - -type DeployJob = - | { - applicationId: string; - titleLog: string; - descriptionLog: string; - server?: boolean; - type: "deploy" | "redeploy"; - applicationType: "application"; - serverId?: string; - } - | { - composeId: string; - titleLog: string; - descriptionLog: string; - server?: boolean; - type: "deploy" | "redeploy"; - applicationType: "compose"; - serverId?: string; - }; - -export type DeploymentJob = DeployJob; +import type { DeploymentJob } from "./queue-types"; +import { redisConfig } from "./redis-connection"; export const deploymentWorker = new Worker( "deployments", @@ -114,25 +93,3 @@ export const deploymentWorker = new Worker( connection: redisConfig, }, ); - -export const cleanQueuesByApplication = async (applicationId: string) => { - const jobs = await myQueue.getJobs(["waiting", "delayed"]); - - for (const job of jobs) { - if (job?.data?.applicationId === applicationId) { - await job.remove(); - console.log(`Removed job ${job.id} for application ${applicationId}`); - } - } -}; - -export const cleanQueuesByCompose = async (composeId: string) => { - const jobs = await myQueue.getJobs(["waiting", "delayed"]); - - for (const job of jobs) { - if (job?.data?.composeId === composeId) { - await job.remove(); - console.log(`Removed job ${job.id} for compose ${composeId}`); - } - } -}; diff --git a/apps/dokploy/server/queues/queue-types.ts b/apps/dokploy/server/queues/queue-types.ts new file mode 100644 index 00000000..f467836a --- /dev/null +++ b/apps/dokploy/server/queues/queue-types.ts @@ -0,0 +1,21 @@ +type DeployJob = + | { + applicationId: string; + titleLog: string; + descriptionLog: string; + server?: boolean; + type: "deploy" | "redeploy"; + applicationType: "application"; + serverId?: string; + } + | { + composeId: string; + titleLog: string; + descriptionLog: string; + server?: boolean; + type: "deploy" | "redeploy"; + applicationType: "compose"; + serverId?: string; + }; + +export type DeploymentJob = DeployJob; diff --git a/apps/dokploy/server/queues/queueSetup.ts b/apps/dokploy/server/queues/queueSetup.ts index 650fbc03..1577273c 100644 --- a/apps/dokploy/server/queues/queueSetup.ts +++ b/apps/dokploy/server/queues/queueSetup.ts @@ -1,8 +1,6 @@ -import { type ConnectionOptions, Queue } from "bullmq"; +import { Queue } from "bullmq"; +import { redisConfig } from "./redis-connection"; -export const redisConfig: ConnectionOptions = { - host: process.env.NODE_ENV === "production" ? "dokploy-redis" : "127.0.0.1", -}; const myQueue = new Queue("deployments", { connection: redisConfig, }); @@ -21,4 +19,26 @@ myQueue.on("error", (error) => { } }); +export const cleanQueuesByApplication = async (applicationId: string) => { + const jobs = await myQueue.getJobs(["waiting", "delayed"]); + + for (const job of jobs) { + if (job?.data?.applicationId === applicationId) { + await job.remove(); + console.log(`Removed job ${job.id} for application ${applicationId}`); + } + } +}; + +export const cleanQueuesByCompose = async (composeId: string) => { + const jobs = await myQueue.getJobs(["waiting", "delayed"]); + + for (const job of jobs) { + if (job?.data?.composeId === composeId) { + await job.remove(); + console.log(`Removed job ${job.id} for compose ${composeId}`); + } + } +}; + export { myQueue }; diff --git a/apps/dokploy/server/queues/redis-connection.ts b/apps/dokploy/server/queues/redis-connection.ts new file mode 100644 index 00000000..104e5f4e --- /dev/null +++ b/apps/dokploy/server/queues/redis-connection.ts @@ -0,0 +1,5 @@ +import type { ConnectionOptions } from "bullmq"; + +export const redisConfig: ConnectionOptions = { + host: process.env.NODE_ENV === "production" ? "dokploy-redis" : "127.0.0.1", +}; diff --git a/apps/dokploy/server/server.ts b/apps/dokploy/server/server.ts index b965cd7c..b65446f8 100644 --- a/apps/dokploy/server/server.ts +++ b/apps/dokploy/server/server.ts @@ -19,10 +19,7 @@ import { setupDockerContainerLogsWebSocketServer } from "./wss/docker-container- import { setupDockerContainerTerminalWebSocketServer } from "./wss/docker-container-terminal"; import { setupDockerStatsMonitoringSocketServer } from "./wss/docker-stats"; import { setupDeploymentLogsWebSocketServer } from "./wss/listen-deployment"; -import { - getPublicIpWithFallback, - setupTerminalWebSocketServer, -} from "./wss/terminal"; +import { setupTerminalWebSocketServer } from "./wss/terminal"; config({ path: ".env" }); const PORT = Number.parseInt(process.env.PORT || "3000", 10); @@ -55,7 +52,6 @@ void app.prepare().then(async () => { await initializeRedis(); initCronJobs(); - welcomeServer(); // Timeout to wait for the database to be ready await new Promise((resolve) => setTimeout(resolve, 7000)); @@ -78,18 +74,3 @@ void app.prepare().then(async () => { console.error("Main Server Error", e); } }); - -async function welcomeServer() { - const ip = await getPublicIpWithFallback(); - console.log( - [ - "", - "", - "Dokploy server is up and running!", - "Please wait for 15 seconds before opening the browser.", - ` http://${ip}:${PORT}`, - "", - "", - ].join("\n"), - ); -} diff --git a/apps/dokploy/server/utils/deploy.ts b/apps/dokploy/server/utils/deploy.ts index f0e4cd78..5acd91a9 100644 --- a/apps/dokploy/server/utils/deploy.ts +++ b/apps/dokploy/server/utils/deploy.ts @@ -1,5 +1,5 @@ import { findServerById } from "@dokploy/server"; -import type { DeploymentJob } from "../queues/deployments-queue"; +import type { DeploymentJob } from "../queues/queue-types"; export const deploy = async (jobData: DeploymentJob) => { try {