mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-09 05:25:18 +00:00
fix(compose): clean up mapping domain labels
This commit is contained in:
@@ -139,6 +139,55 @@ describe("addDomainToCompose enabled filtering", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[
|
||||||
|
"docker-compose",
|
||||||
|
`services:
|
||||||
|
frigate:
|
||||||
|
image: frigate
|
||||||
|
labels:
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.http.routers.test-app-1-web.rule: Host(\`frigate.example.com\`)
|
||||||
|
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
|
||||||
|
traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes: /api
|
||||||
|
custom.label: preserved
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"stack",
|
||||||
|
`services:
|
||||||
|
frigate:
|
||||||
|
image: frigate
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.http.routers.test-app-1-web.rule: Host(\`frigate.example.com\`)
|
||||||
|
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
|
||||||
|
traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes: /api
|
||||||
|
custom.label: preserved
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
] as const)(
|
||||||
|
"removes stale mapping labels for a disabled domain from %s rebuilds",
|
||||||
|
async (composeType, staleComposeYaml) => {
|
||||||
|
composeYaml = staleComposeYaml;
|
||||||
|
|
||||||
|
const result = await addDomainToCompose({ ...baseCompose, composeType }, [
|
||||||
|
{ ...baseDomain, enabled: false },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const service = result?.services?.frigate;
|
||||||
|
const labels =
|
||||||
|
composeType === "docker-compose"
|
||||||
|
? service?.labels
|
||||||
|
: service?.deploy?.labels;
|
||||||
|
expect(labels).toMatchObject({ "custom.label": "preserved" });
|
||||||
|
expect(
|
||||||
|
Object.keys(labels ?? {}).some((label) => label.includes("test-app-1")),
|
||||||
|
).toBe(false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it("emits labels only for the enabled domain when both are present", async () => {
|
it("emits labels only for the enabled domain when both are present", async () => {
|
||||||
const result = await addDomainToCompose(baseCompose, [
|
const result = await addDomainToCompose(baseCompose, [
|
||||||
{ ...baseDomain, host: "enabled.example.com", enabled: true },
|
{ ...baseDomain, host: "enabled.example.com", enabled: true },
|
||||||
|
|||||||
@@ -171,18 +171,25 @@ const removeDomainLabels = (
|
|||||||
appName: string,
|
appName: string,
|
||||||
uniqueConfigKey: number,
|
uniqueConfigKey: number,
|
||||||
) => {
|
) => {
|
||||||
if (!Array.isArray(labels)) return labels;
|
|
||||||
|
|
||||||
const prefixes = [
|
const prefixes = [
|
||||||
`traefik.http.routers.${appName}-${uniqueConfigKey}-`,
|
`traefik.http.routers.${appName}-${uniqueConfigKey}-`,
|
||||||
`traefik.http.services.${appName}-${uniqueConfigKey}-`,
|
`traefik.http.services.${appName}-${uniqueConfigKey}-`,
|
||||||
`traefik.http.middlewares.stripprefix-${appName}-${uniqueConfigKey}.`,
|
`traefik.http.middlewares.stripprefix-${appName}-${uniqueConfigKey}.`,
|
||||||
`traefik.http.middlewares.addprefix-${appName}-${uniqueConfigKey}.`,
|
`traefik.http.middlewares.addprefix-${appName}-${uniqueConfigKey}.`,
|
||||||
];
|
];
|
||||||
|
const belongsToDomain = (label: string) =>
|
||||||
|
prefixes.some((prefix) => label.startsWith(prefix));
|
||||||
|
|
||||||
return labels.filter(
|
if (Array.isArray(labels)) {
|
||||||
(label) => !prefixes.some((prefix) => label.startsWith(prefix)),
|
return labels.filter((label) => !belongsToDomain(label));
|
||||||
);
|
}
|
||||||
|
if (labels) {
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(labels).filter(([label]) => !belongsToDomain(label)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return labels;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addDomainToCompose = async (
|
export const addDomainToCompose = async (
|
||||||
|
|||||||
Reference in New Issue
Block a user