mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-02 02:02:18 +00:00
fix(compose): regenerate mapping domain labels
This commit is contained in:
@@ -237,6 +237,59 @@ 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(\`old.example.com\`)
|
||||||
|
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
|
||||||
|
custom.label: preserved
|
||||||
|
`,
|
||||||
|
"traefik.docker.network",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"stack",
|
||||||
|
`services:
|
||||||
|
frigate:
|
||||||
|
image: frigate
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.http.routers.test-app-1-web.rule: Host(\`old.example.com\`)
|
||||||
|
traefik.http.services.test-app-1-web.loadbalancer.server.port: 8971
|
||||||
|
custom.label: preserved
|
||||||
|
`,
|
||||||
|
"traefik.swarm.network",
|
||||||
|
],
|
||||||
|
] as const)(
|
||||||
|
"regenerates routing in mapping labels for an enabled domain in %s",
|
||||||
|
async (composeType, mappingComposeYaml, networkLabel) => {
|
||||||
|
composeYaml = mappingComposeYaml;
|
||||||
|
|
||||||
|
const result = await addDomainToCompose({ ...baseCompose, composeType }, [
|
||||||
|
{ ...baseDomain, enabled: true },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const service = result?.services?.frigate;
|
||||||
|
const labels =
|
||||||
|
composeType === "docker-compose"
|
||||||
|
? service?.labels
|
||||||
|
: service?.deploy?.labels;
|
||||||
|
expect(labels).toMatchObject({
|
||||||
|
"custom.label": "preserved",
|
||||||
|
"traefik.enable": "true",
|
||||||
|
[networkLabel]: "dokploy-network",
|
||||||
|
"traefik.http.routers.test-app-1-web.rule":
|
||||||
|
"Host(`frigate.example.com`)",
|
||||||
|
"traefik.http.services.test-app-1-web.loadbalancer.server.port": "8971",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
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 },
|
||||||
|
|||||||
@@ -282,33 +282,31 @@ export const addDomainToCompose = async (
|
|||||||
labels = result.services[serviceName].deploy.labels;
|
labels = result.services[serviceName].deploy.labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const networkLabel =
|
||||||
|
compose.composeType === "docker-compose"
|
||||||
|
? "traefik.docker.network"
|
||||||
|
: "traefik.swarm.network";
|
||||||
|
const networkName = compose.isolatedDeployment
|
||||||
|
? compose.suffix || compose.appName
|
||||||
|
: "dokploy-network";
|
||||||
|
|
||||||
if (Array.isArray(labels)) {
|
if (Array.isArray(labels)) {
|
||||||
if (!labels.includes("traefik.enable=true")) {
|
if (!labels.includes("traefik.enable=true")) {
|
||||||
labels.unshift("traefik.enable=true");
|
labels.unshift("traefik.enable=true");
|
||||||
}
|
}
|
||||||
labels.unshift(...httpLabels);
|
labels.unshift(...httpLabels);
|
||||||
if (!compose.isolatedDeployment) {
|
const networkLabelEntry = `${networkLabel}=${networkName}`;
|
||||||
if (compose.composeType === "docker-compose") {
|
if (!labels.includes(networkLabelEntry)) {
|
||||||
if (!labels.includes("traefik.docker.network=dokploy-network")) {
|
labels.unshift(networkLabelEntry);
|
||||||
labels.unshift("traefik.docker.network=dokploy-network");
|
}
|
||||||
}
|
} else if (labels) {
|
||||||
} else {
|
labels["traefik.enable"] = "true";
|
||||||
// Stack Case
|
labels[networkLabel] = networkName;
|
||||||
if (!labels.includes("traefik.swarm.network=dokploy-network")) {
|
for (const label of httpLabels) {
|
||||||
labels.unshift("traefik.swarm.network=dokploy-network");
|
const separatorIndex = label.indexOf("=");
|
||||||
}
|
labels[label.slice(0, separatorIndex)] = label.slice(
|
||||||
}
|
separatorIndex + 1,
|
||||||
} else {
|
);
|
||||||
const isolatedNetwork = compose.suffix || compose.appName;
|
|
||||||
if (compose.composeType === "docker-compose") {
|
|
||||||
if (!labels.includes(`traefik.docker.network=${isolatedNetwork}`)) {
|
|
||||||
labels.unshift(`traefik.docker.network=${isolatedNetwork}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!labels.includes(`traefik.swarm.network=${isolatedNetwork}`)) {
|
|
||||||
labels.unshift(`traefik.swarm.network=${isolatedNetwork}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user