From 105562bdcb415e070d394b979ca34592c421b525 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 7 Feb 2026 19:42:14 -0600 Subject: [PATCH] feat(traefik): implement reconnectServicesToTraefik function - Added a new function `reconnectServicesToTraefik` to facilitate the reconnection of services to Traefik based on the server ID. - The function queries the database for isolated deployments and constructs Docker network connect commands for each service. - Enhanced the existing Traefik setup process by ensuring services are properly reconnected after setup. --- packages/server/src/services/settings.ts | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/server/src/services/settings.ts b/packages/server/src/services/settings.ts index 0ce252308..60ece860b 100644 --- a/packages/server/src/services/settings.ts +++ b/packages/server/src/services/settings.ts @@ -4,7 +4,9 @@ import { execAsync, execAsyncRemote, } from "@dokploy/server/utils/process/execAsync"; +import { and, eq } from "drizzle-orm"; import semver from "semver"; +import { compose } from "../db/schema"; import { initializeStandaloneTraefik, initializeTraefikService, @@ -438,13 +440,40 @@ export const writeTraefikSetup = async (input: TraefikOptions) => { additionalPorts: input.additionalPorts, serverId: input.serverId, }); + await reconnectServicesToTraefik(input.serverId); } else if (resourceType === "standalone") { await initializeStandaloneTraefik({ env: input.env, additionalPorts: input.additionalPorts, serverId: input.serverId, }); + + await reconnectServicesToTraefik(input.serverId); } else { throw new Error("Traefik resource type not found"); } }; + +export const reconnectServicesToTraefik = async (serverId?: string) => { + const composeResult = await db?.query.compose.findMany({ + where: and( + ...(serverId ? [eq(compose.serverId, serverId)] : []), + eq(compose.isolatedDeployment, true), + ), + }); + + if (!composeResult) { + return; + } + let commands = ""; + + for (const compose of composeResult) { + commands += `docker network connect ${compose.appName} $(docker ps --filter "name=dokploy-traefik" -q) >/dev/null 2>&1\n`; + } + + if (serverId) { + await execAsyncRemote(serverId, commands); + } else { + await execAsync(commands); + } +};