Remove old docker images correctly

Old images had no sha256, so it prints "<none>". These images
have to be accessed by tag which uses the ":tag" format whereas
the sha images use the "@sha" format
This commit is contained in:
Girish Ramakrishnan
2018-09-17 16:32:07 -07:00
parent 691b876d61
commit 3c6dffbbc7
+2 -1
View File
@@ -119,7 +119,8 @@ function removeOldImages(callback) {
const image = infra.images[imageName];
const tag = image.tag.replace(/:.*@/, '@'); // this remove the semver tag
debug('cleaning up images of %j', image);
const cmd = `docker images --digests "${image.repo}" | tail -n +2 | awk '{ print $1 "@" $3 }' | grep -v "${tag}" | xargs --no-run-if-empty docker rmi`;
// 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);
}