apps: rework portBindings

ports is REST API input . Map of env var to the host port
portBinding is the database structure. Map of env var to host port, count, type etc

also, rename portCount -> count in various places to keep things consistent
This commit is contained in:
Girish Ramakrishnan
2024-07-16 22:21:36 +02:00
parent eb314ef507
commit aeddaa4566
12 changed files with 151 additions and 147 deletions

View File

@@ -285,11 +285,9 @@ async function createSubcontainer(app, name, cmd, options) {
const portEnv = [];
for (const portName in app.portBindings) {
const hostPort = app.portBindings[portName];
const portType = (manifest.tcpPorts && portName in manifest.tcpPorts) ? 'tcp' : 'udp';
const ports = portType == 'tcp' ? manifest.tcpPorts : manifest.udpPorts;
const containerPort = ports[portName].containerPort || hostPort;
const portCount = ports[portName].portCount || 1;
const { hostPort, type:portType, count:portCount } = app.portBindings[portName];
const portSpec = portType == 'tcp' ? manifest.tcpPorts : manifest.udpPorts;
const containerPort = portSpec[portName].containerPort || hostPort;
const hostIps = hostPort === 53 ? await getAddressesForPort53() : [ '0.0.0.0', '::0' ]; // port 53 is special because it is possibly taken by systemd-resolved
portEnv.push(`${portName}=${hostPort}`);
@@ -298,7 +296,7 @@ async function createSubcontainer(app, name, cmd, options) {
// docker portBindings requires ports to be exposed
for (let i = 0; i < portCount; ++i) {
exposedPorts[`${containerPort+i}/${portType}`] = {};
dockerPortBindings[`${containerPort+i}/${portType}`] = hostIps.map(hip => { return { HostIp: hip, HostPort: (hostPort + i) + '' }; });
dockerPortBindings[`${containerPort+i}/${portType}`] = hostIps.map(hip => { return { HostIp: hip, HostPort: String(hostPort + i) }; });
}
}
@@ -348,7 +346,7 @@ async function createSubcontainer(app, name, cmd, options) {
},
Memory: memoryLimit,
MemorySwap: -1, // Unlimited swap
PortBindings: isAppContainer ? dockerPortBindings : { },
PortBindings: isAppContainer ? dockerPortBindings : {},
PublishAllPorts: false,
ReadonlyRootfs: app.debugMode ? !!app.debugMode.readonlyRootfs : true,
RestartPolicy: {