Use docker cli to cleanup old images

This commit is contained in:
Girish Ramakrishnan
2018-10-25 16:32:35 -07:00
parent 2e3ddba7e5
commit e3478c9d13

View File

@@ -95,14 +95,7 @@ function emitPlatformReady() {
function removeOldImages(callback) {
debug('removing old addon images');
for (var imageName in infra.images) {
const image = infra.images[imageName];
const tag = image.tag.replace(/:.*@/, '@'); // this remove the semver tag
debug('cleaning up images of %j', image);
// older docker images did not have sha256 and thus have it as <none>
const cmd = `docker images --digests "${image.repo}" | tail -n +2 | awk '{ print $1 ($3=="<none>" ? (":" $2) : ("@" $3)) }' | grep -v "${tag}" | xargs --no-run-if-empty docker rmi`;
shell.execSync('removeOldImagesSync', cmd);
}
shell.execSync('removeOldImagesSync', 'docker image prune --force --all');
callback();
}