fix(settings): prevent duplicate port entries by only adding the first mapping for each target port

This commit is contained in:
Mauricio Siu
2025-12-06 14:23:43 -06:00
parent 4873baa975
commit 7ea7ee739f

View File

@@ -372,19 +372,27 @@ export const readPorts = async (
publishedPort: number; publishedPort: number;
protocol?: string; protocol?: string;
}[] = []; }[] = [];
const seenPorts = new Set<string>();
for (const key in parsedResult) { for (const key in parsedResult) {
if (Object.hasOwn(parsedResult, key)) { if (Object.hasOwn(parsedResult, key)) {
const containerPortMapppings = parsedResult[key]; const containerPortMapppings = parsedResult[key];
const protocol = key.split("/")[1]; const protocol = key.split("/")[1];
const targetPort = Number.parseInt(key.split("/")[0] ?? "0", 10); const targetPort = Number.parseInt(key.split("/")[0] ?? "0", 10);
containerPortMapppings.forEach((mapping: any) => { // Take only the first mapping to avoid duplicates (IPv4 and IPv6)
ports.push({ const firstMapping = containerPortMapppings[0];
targetPort: targetPort, if (firstMapping) {
publishedPort: Number.parseInt(mapping.HostPort, 10), const publishedPort = Number.parseInt(firstMapping.HostPort, 10);
protocol: protocol, const portKey = `${targetPort}-${publishedPort}-${protocol}`;
}); if (!seenPorts.has(portKey)) {
}); seenPorts.add(portKey);
ports.push({
targetPort: targetPort,
publishedPort: publishedPort,
protocol: protocol,
});
}
}
} }
} }
return ports.filter( return ports.filter(