diff --git a/src/platform.js b/src/platform.js index a5edfbcfd..f252dc4d3 100644 --- a/src/platform.js +++ b/src/platform.js @@ -14,7 +14,8 @@ var apps = require('./apps.js'), path = require('path'), paths = require('./paths.js'), safe = require('safetydance'), - shell = require('./shell.js'); + shell = require('./shell.js'), + util = require('util'); var SETUP_INFRA_CMD = path.join(__dirname, 'scripts/setup_infra.sh'); @@ -43,6 +44,8 @@ function initialize(callback) { startAddons(function (error) { if (error) return callback(error); + removeOldImagesSync(); + var func = existingInfra ? apps.configureInstalledApps : apps.restoreInstalledApps; func(function (error) { @@ -55,6 +58,17 @@ function initialize(callback) { }); } +function removeOldImagesSync() { + debug('removing old addon images'); + + for (var imageName in infra.images) { + var image = infra.images[imageName]; + debug('cleaning up images of %s', image); + var cmd = 'docker images "%s" | tail -n +2 | awk \'{ print $1 ":" $2 }\' | grep -v "%s" | xargs --no-run-if-empty docker rmi'; + shell.execSync('removeOldImagesSync', util.format(cmd, image.repo, image.tag)); + } +} + function removeImagesSync() { debug('removing existing images'); shell.execSync('removeImagesSync', 'docker images -q | xargs --no-run-if-empty docker rmi -f'); diff --git a/src/scripts/setup_infra.sh b/src/scripts/setup_infra.sh index 27094dfd2..040a06ec3 100755 --- a/src/scripts/setup_infra.sh +++ b/src/scripts/setup_infra.sh @@ -32,9 +32,6 @@ graphite_container_id=$(docker run --restart=always -d --name="graphite" \ --read-only -v /tmp -v /run \ "${GRAPHITE_IMAGE}") echo "Graphite container id: ${graphite_container_id}" -if docker images "${GRAPHITE_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${GRAPHITE_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old graphite images" -fi # mail (note: 2525 is hardcoded in mail container and app use this port) # MAIL_SERVER_NAME is the hostname of the mailserver i.e server uses these certs @@ -55,9 +52,6 @@ mail_container_id=$(docker run --restart=always -d --name="mail" \ --read-only -v /tmp -v /run \ "${MAIL_IMAGE}") echo "Mail container id: ${mail_container_id}" -if docker images "${MAIL_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${MAIL_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old mail images" -fi # mysql mysql_addon_root_password=$(pwgen -1 -s) @@ -75,9 +69,6 @@ mysql_container_id=$(docker run --restart=always -d --name="mysql" \ --read-only -v /tmp -v /run \ "${MYSQL_IMAGE}") echo "MySQL container id: ${mysql_container_id}" -if docker images "${MYSQL_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${MYSQL_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old mysql images" -fi # postgresql postgresql_addon_root_password=$(pwgen -1 -s) @@ -93,9 +84,6 @@ postgresql_container_id=$(docker run --restart=always -d --name="postgresql" \ --read-only -v /tmp -v /run \ "${POSTGRESQL_IMAGE}") echo "PostgreSQL container id: ${postgresql_container_id}" -if docker images "${POSTGRESQL_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${POSTGRESQL_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old postgresql images" -fi # mongodb mongodb_addon_root_password=$(pwgen -1 -s) @@ -111,11 +99,3 @@ mongodb_container_id=$(docker run --restart=always -d --name="mongodb" \ --read-only -v /tmp -v /run \ "${MONGODB_IMAGE}") echo "Mongodb container id: ${mongodb_container_id}" -if docker images "${MONGODB_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${MONGODB_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old mongodb images" -fi - -# redis -if docker images "${REDIS_REPO}" | tail -n +2 | awk '{ print $1 ":" $2 }' | grep -v "${REDIS_IMAGE}" | xargs --no-run-if-empty docker rmi; then - echo "Removed old redis images" -fi