test: enforce production docker network invariants

This commit is contained in:
Bastian Wagner
2026-08-17 13:45:14 +02:00
parent 5edb16de73
commit ccea4e48ec
4 changed files with 68 additions and 15 deletions

View File

@@ -0,0 +1,18 @@
export function verifyComposeInvariants(compose) {
const services = compose?.services ?? {};
for (const [name, service] of Object.entries(services)) {
if (name !== 'edge' && Array.isArray(service.ports) && service.ports.length > 0) {
throw new Error(`${name} must not define ports`);
}
if (service.network_mode === 'host') {
throw new Error(`${name} must not use network_mode: host`);
}
}
const edge = services.edge;
const edgePorts = Array.isArray(edge?.ports) ? edge.ports : [];
if (edgePorts.length !== 1) {
throw new Error(`edge must publish exactly one port; found ${edgePorts.length}`);
}
}