Skip to content

Commit f14f12c

Browse files
committed
fix(compose): clean up mapping domain labels
1 parent 37c8d64 commit f14f12c

2 files changed

Lines changed: 61 additions & 5 deletions

File tree

‎apps/dokploy/__test__/compose/domain/enabled-filter.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,55 @@ describe("addDomainToCompose enabled filtering", () => {
139139
},
140140
);
141141

142+
it.each([
143+
[
144+
"docker-compose",
145+
`services:
146+
frigate:
147+
image: frigate
148+
labels:
149+
traefik.enable: "true"
150+
traefik.http.routers.test-app-1-web.rule: Host(\`frigate.example.com\`)
151+
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
152+
traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes: /api
153+
custom.label: preserved
154+
`,
155+
],
156+
[
157+
"stack",
158+
`services:
159+
frigate:
160+
image: frigate
161+
deploy:
162+
labels:
163+
traefik.enable: "true"
164+
traefik.http.routers.test-app-1-web.rule: Host(\`frigate.example.com\`)
165+
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
166+
traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes: /api
167+
custom.label: preserved
168+
`,
169+
],
170+
] as const)(
171+
"removes stale mapping labels for a disabled domain from %s rebuilds",
172+
async (composeType, staleComposeYaml) => {
173+
composeYaml = staleComposeYaml;
174+
175+
const result = await addDomainToCompose({ ...baseCompose, composeType }, [
176+
{ ...baseDomain, enabled: false },
177+
]);
178+
179+
const service = result?.services?.frigate;
180+
const labels =
181+
composeType === "docker-compose"
182+
? service?.labels
183+
: service?.deploy?.labels;
184+
expect(labels).toMatchObject({ "custom.label": "preserved" });
185+
expect(
186+
Object.keys(labels ?? {}).some((label) => label.includes("test-app-1")),
187+
).toBe(false);
188+
},
189+
);
190+
142191
it("emits labels only for the enabled domain when both are present", async () => {
143192
const result = await addDomainToCompose(baseCompose, [
144193
{ ...baseDomain, host: "enabled.example.com", enabled: true },

‎packages/server/src/utils/docker/domain.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,25 @@ const removeDomainLabels = (
171171
appName: string,
172172
uniqueConfigKey: number,
173173
) => {
174-
if (!Array.isArray(labels)) return labels;
175-
176174
const prefixes = [
177175
`traefik.http.routers.${appName}-${uniqueConfigKey}-`,
178176
`traefik.http.services.${appName}-${uniqueConfigKey}-`,
179177
`traefik.http.middlewares.stripprefix-${appName}-${uniqueConfigKey}.`,
180178
`traefik.http.middlewares.addprefix-${appName}-${uniqueConfigKey}.`,
181179
];
180+
const belongsToDomain = (label: string) =>
181+
prefixes.some((prefix) => label.startsWith(prefix));
182182

183-
return labels.filter(
184-
(label) => !prefixes.some((prefix) => label.startsWith(prefix)),
185-
);
183+
if (Array.isArray(labels)) {
184+
return labels.filter((label) => !belongsToDomain(label));
185+
}
186+
if (labels) {
187+
return Object.fromEntries(
188+
Object.entries(labels).filter(([label]) => !belongsToDomain(label)),
189+
);
190+
}
191+
192+
return labels;
186193
};
187194

188195
export const addDomainToCompose = async (

0 commit comments

Comments
 (0)