Skip to content

Commit f4b5a58

Browse files
authored
Merge pull request #3635 from Dokploy/3313-traefik-loses-all-bridge-network-connections-when-modifying-port-mappings-or-toggling-dashboard
feat(traefik): implement reconnectServicesToTraefik function
2 parents 16359e2 + 105562b commit f4b5a58

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/server/src/services/settings.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
execAsync,
55
execAsyncRemote,
66
} from "@dokploy/server/utils/process/execAsync";
7+
import { and, eq } from "drizzle-orm";
78
import semver from "semver";
9+
import { compose } from "../db/schema";
810
import {
911
initializeStandaloneTraefik,
1012
initializeTraefikService,
@@ -438,13 +440,40 @@ export const writeTraefikSetup = async (input: TraefikOptions) => {
438440
additionalPorts: input.additionalPorts,
439441
serverId: input.serverId,
440442
});
443+
await reconnectServicesToTraefik(input.serverId);
441444
} else if (resourceType === "standalone") {
442445
await initializeStandaloneTraefik({
443446
env: input.env,
444447
additionalPorts: input.additionalPorts,
445448
serverId: input.serverId,
446449
});
450+
451+
await reconnectServicesToTraefik(input.serverId);
447452
} else {
448453
throw new Error("Traefik resource type not found");
449454
}
450455
};
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

Comments
 (0)