From 67fa8e4104b372fdd8cfd76d9c2c2cc4e4de4f57 Mon Sep 17 00:00:00 2001 From: Vyacheslav Scherbinin Date: Tue, 11 Aug 2026 11:16:44 +0700 Subject: [PATCH] fix(compose): clean domain labels across services --- .../compose/domain/enabled-filter.test.ts | 49 +++++++++++++++++++ packages/server/src/utils/docker/domain.ts | 33 ++++++------- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/apps/dokploy/__test__/compose/domain/enabled-filter.test.ts b/apps/dokploy/__test__/compose/domain/enabled-filter.test.ts index c581dcdc0..47de73f31 100644 --- a/apps/dokploy/__test__/compose/domain/enabled-filter.test.ts +++ b/apps/dokploy/__test__/compose/domain/enabled-filter.test.ts @@ -139,6 +139,55 @@ describe("addDomainToCompose enabled filtering", () => { }, ); + it.each([ + [ + "docker-compose", + `services: + legacy: + image: frigate + labels: + - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`) + - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971 + - custom.label=preserved + frigate: + image: frigate +`, + ], + [ + "stack", + `services: + legacy: + image: frigate + deploy: + labels: + - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`) + - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971 + - custom.label=preserved + frigate: + image: frigate +`, + ], + ] as const)( + "removes stale labels from the previous %s service after reassignment", + async (composeType, staleComposeYaml) => { + composeYaml = staleComposeYaml; + + const result = await addDomainToCompose({ ...baseCompose, composeType }, [ + { ...baseDomain, serviceName: "frigate", enabled: false }, + ]); + + const previousService = result?.services?.legacy; + const labels = + composeType === "docker-compose" + ? previousService?.labels + : previousService?.deploy?.labels; + expect(labels).toContain("custom.label=preserved"); + expect( + (labels as string[]).some((label) => label.includes("test-app-1")), + ).toBe(false); + }, + ); + it.each([ [ "docker-compose", diff --git a/packages/server/src/utils/docker/domain.ts b/packages/server/src/utils/docker/domain.ts index 6c8443987..d7b891475 100644 --- a/packages/server/src/utils/docker/domain.ts +++ b/packages/server/src/utils/docker/domain.ts @@ -224,24 +224,21 @@ export const addDomainToCompose = async ( result = randomized; } - for (const domain of domains.filter((d) => !d.enabled)) { - if (!domain.serviceName) continue; - - const service = result.services?.[domain.serviceName]; - if (!service) continue; - - if (compose.composeType === "docker-compose") { - service.labels = removeDomainLabels( - service.labels, - appName, - domain.uniqueConfigKey, - ); - } else if (service.deploy) { - service.deploy.labels = removeDomainLabels( - service.deploy.labels, - appName, - domain.uniqueConfigKey, - ); + for (const domain of domains) { + for (const service of Object.values(result.services ?? {})) { + if (compose.composeType === "docker-compose") { + service.labels = removeDomainLabels( + service.labels, + appName, + domain.uniqueConfigKey, + ); + } else if (service.deploy) { + service.deploy.labels = removeDomainLabels( + service.deploy.labels, + appName, + domain.uniqueConfigKey, + ); + } } }