From 4ab84d42c66f4945d8763a87dff8cebde04107b1 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 19 Aug 2015 14:16:01 -0700 Subject: [PATCH] Delete image only if it changed This optimization won't work if we have two dockerImage with same image id.... --- src/apptask.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/apptask.js b/src/apptask.js index 89756a9aa..58bbffefe 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -248,7 +248,7 @@ function deleteImage(app, manifest, callback) { noprune: false }; - // delete image by id because docker pull pulls down all the tags and this is the only way to delete all tags + // delete image by id because 'docker pull' pulls down all the tags and this is the only way to delete all tags docker.getImage(result.Id).remove(removeOptions, function (error) { if (error && error.statusCode === 404) return callback(null); if (error && error.statusCode === 409) return callback(null); // another container using the image @@ -622,7 +622,11 @@ function restore(app, callback) { // oldConfig can be null during upgrades addons.teardownAddons.bind(null, app, app.oldConfig ? app.oldConfig.manifest.addons : null), deleteVolume.bind(null, app), - deleteImage.bind(null, app, app.manifest), + function deleteImageIfChanged(done) { + if (app.oldConfig.manifest.dockerImage === app.manifest.dockerImage) return done(); + + deleteImage(app, app.oldConfig.manifest, done); + }, removeOAuthProxyCredentials.bind(null, app), removeIcon.bind(null, app), unconfigureNginx.bind(null, app), @@ -759,7 +763,11 @@ function update(app, callback) { stopApp.bind(null, app), deleteContainer.bind(null, app), addons.teardownAddons.bind(null, app, unusedAddons), - deleteImage.bind(null, app, app.oldConfig.manifest), // delete old image even if did not change (see df158b111f) + function deleteImageIfChanged(done) { + if (app.oldConfig.manifest.dockerImage === app.manifest.dockerImage) return done(); + + deleteImage(app, app.oldConfig.manifest, done); + }, // removeIcon.bind(null, app), // do not remove icon, otherwise the UI breaks for a short time... function (next) {