statically allocate app container IPs

We removed httpPort with the assumption that docker allocated IPs
and kept them as long as the container is around. This turned out
to be not true because the IP changes on even container restart.

So we now allocate IPs statically. The iprange makes sure we don't
overlap with addons and other CI app or JupyterHub apps.

https://github.com/moby/moby/issues/6743
https://github.com/moby/moby/pull/19001
This commit is contained in:
Girish Ramakrishnan
2020-11-20 14:13:16 -08:00
parent 64af278f39
commit c0b0029935
13 changed files with 165 additions and 59 deletions

View File

@@ -54,7 +54,8 @@ function start(callback) {
if (error) return callback(error);
async.series([
(next) => { if (existingInfra.version !== infra.version) removeAllContainers(existingInfra, next); else next(); },
(next) => { if (existingInfra.version !== infra.version) removeAllContainers(next); else next(); },
createDockerNetwork,
markApps.bind(null, existingInfra), // mark app state before we start addons. this gives the db import logic a chance to mark an app as errored
graphs.startGraphite.bind(null, existingInfra),
sftp.startSftp.bind(null, existingInfra),
@@ -122,7 +123,7 @@ function pruneInfraImages(callback) {
}, callback);
}
function removeAllContainers(existingInfra, callback) {
function removeAllContainers(callback) {
debug('removeAllContainers: removing all containers for infra upgrade');
async.series([
@@ -131,6 +132,16 @@ function removeAllContainers(existingInfra, callback) {
], callback);
}
function createDockerNetwork(callback) {
debug('createDockerNetwork: creating cloudron network');
// this gives docker the network range 172.18.0.0-172.18.15.255
async.series([
shell.exec.bind(null, 'createDockerNetwork', 'docker network rm cloudron || true'), // may not exist on first run
shell.exec.bind(null, 'createDockerNetwork', 'docker network create --subnet=172.18.0.0/16 --ip-range=172.18.0.0/20 cloudron || true') // can fail if (user) containers are still attached
], callback);
}
function markApps(existingInfra, callback) {
if (existingInfra.version === 'none') { // cloudron is being restored from backup
debug('markApps: restoring installed apps');