|
4 | 4 | execAsync, |
5 | 5 | execAsyncRemote, |
6 | 6 | } from "@dokploy/server/utils/process/execAsync"; |
| 7 | +import { and, eq } from "drizzle-orm"; |
7 | 8 | import semver from "semver"; |
| 9 | +import { compose } from "../db/schema"; |
8 | 10 | import { |
9 | 11 | initializeStandaloneTraefik, |
10 | 12 | initializeTraefikService, |
@@ -438,13 +440,40 @@ export const writeTraefikSetup = async (input: TraefikOptions) => { |
438 | 440 | additionalPorts: input.additionalPorts, |
439 | 441 | serverId: input.serverId, |
440 | 442 | }); |
| 443 | + await reconnectServicesToTraefik(input.serverId); |
441 | 444 | } else if (resourceType === "standalone") { |
442 | 445 | await initializeStandaloneTraefik({ |
443 | 446 | env: input.env, |
444 | 447 | additionalPorts: input.additionalPorts, |
445 | 448 | serverId: input.serverId, |
446 | 449 | }); |
| 450 | + |
| 451 | + await reconnectServicesToTraefik(input.serverId); |
447 | 452 | } else { |
448 | 453 | throw new Error("Traefik resource type not found"); |
449 | 454 | } |
450 | 455 | }; |
| 456 | + |
| 457 | +export const reconnectServicesToTraefik = async (serverId?: string) => { |
| 458 | + const composeResult = await db?.query.compose.findMany({ |
| 459 | + where: and( |
| 460 | + ...(serverId ? [eq(compose.serverId, serverId)] : []), |
| 461 | + eq(compose.isolatedDeployment, true), |
| 462 | + ), |
| 463 | + }); |
| 464 | + |
| 465 | + if (!composeResult) { |
| 466 | + return; |
| 467 | + } |
| 468 | + let commands = ""; |
| 469 | + |
| 470 | + for (const compose of composeResult) { |
| 471 | + commands += `docker network connect ${compose.appName} $(docker ps --filter "name=dokploy-traefik" -q) >/dev/null 2>&1\n`; |
| 472 | + } |
| 473 | + |
| 474 | + if (serverId) { |
| 475 | + await execAsyncRemote(serverId, commands); |
| 476 | + } else { |
| 477 | + await execAsync(commands); |
| 478 | + } |
| 479 | +}; |
0 commit comments