From 8f9c1277abf7f73bece04b97484c9d796dd7a1e5 Mon Sep 17 00:00:00 2001 From: Jirka Kremser Date: Thu, 30 May 2019 21:03:29 +0200 Subject: [PATCH] Instead of using fixed number of layers we want to squash, squash all of them up to the first four. --- .travis.release.images.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.release.images.sh b/.travis.release.images.sh index 7fddb2e..27cbbcc 100755 --- a/.travis.release.images.sh +++ b/.travis.release.images.sh @@ -7,7 +7,6 @@ IMAGES="${IMAGES:- openshift-spark openshift-spark-py36 openshift-spark-inc - openshift-spark-py36-inc }" main() { @@ -57,13 +56,22 @@ squashAndPush() { if [[ $# != 2 ]]; then echo "Usage: squashAndPush input_image output_image" && exit fi + set +e local _in=$1 local _out=$2 - echo "Squashing $_out.." - # squash last 22 layers (everything up to the base centos image) - docker-squash -f 22 -t $_out $_in + local _layers_total=$(docker history -q $_in | wc -l) + local _layers_to_keep=4 + + if [[ ! "$_layers_total" =~ ^[0-9]+$ ]] || [[ "$_layers_total" -le "$_layers_to_keep" ]] ; then + echo "error: _layers_total ('$_layers_total') is not a number or lower than or equal to $_layers_to_keep" >&2; return + fi + local _last_n=$[_layers_total - _layers_to_keep] + + echo "Squashing $_out (last $_last_n layers).." + docker-squash -f $_last_n -t $_out $_in docker push $_out + set -e } pushLatestImages() {