remove old images in platform.js

This commit is contained in:
Girish Ramakrishnan
2016-05-24 13:16:31 -07:00
parent 4845db538a
commit 7fb28662c1
2 changed files with 15 additions and 21 deletions

View File

@@ -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');