Skip to content

Commit 7456e13

Browse files
committed
Instead of using fixed number of layers we want to squash, squash all of them up to the first four.
1 parent 3c6ac3b commit 7456e13

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

.travis.release.images.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ main() {
1818
loginDockerIo
1919
pushLatestImages "docker.io"
2020
loginQuayIo
21-
pushLatestImages "quay.io"
21+
pushLatestImages "quay.io"
2222
elif [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$ ]]; then
2323
echo "Squashing and pushing the '${TRAVIS_TAG}' images to docker.io and quay.io"
2424
buildImages
@@ -60,9 +60,16 @@ squashAndPush() {
6060
local _in=$1
6161
local _out=$2
6262

63-
echo "Squashing $_out.."
64-
# squash last 22 layers (everything up to the base centos image)
65-
docker-squash -f 22 -t $_out $_in
63+
local _layers_total=$(docker history -q $_in | wc -l)
64+
local _layers_to_keep=4
65+
66+
if [[ ! "$_layers_total" =~ ^[0-9]+$ ]] || [[ "$_layers_total" -le "$_layers_to_keep" ]] ; then
67+
echo "error: _layers_total ('$_layers_total') is not a number or lower than or equal to $_layers_to_keep" >&2; exit
68+
fi
69+
local _last_n=$[_layers_total - _layers_to_keep]
70+
71+
echo "Squashing $_out (last $_last_n layers).."
72+
docker-squash -f $_last_n -t $_out $_in
6673
docker push $_out
6774
}
6875

0 commit comments

Comments
 (0)