Skip to content

Commit 1172bf1

Browse files
committed
Cache Docker images between builds to speed up setup phase
1 parent c41cc6c commit 1172bf1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

travis/travis-docker.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ esac
2020

2121
cd $(readlink -f $(dirname "$0"))
2222

23-
IMAGE=appimagelauncher-build:"$DOCKER_DIST"
23+
IMAGE=quay.io/appimagelauncher-build/"$DOCKER_DIST"
2424
DOCKERFILE=Dockerfile.build-"$DOCKER_DIST"
2525

2626
if [ ! -f "$DOCKERFILE" ]; then
@@ -29,11 +29,15 @@ if [ ! -f "$DOCKERFILE" ]; then
2929
fi
3030

3131
if [ "$ARCH" == "i386" ]; then
32-
IMAGE=appimagelauncher-build:"$DOCKER_DIST"-i386-cross
32+
IMAGE="$IMAGE"-i386-cross
3333
DOCKERFILE=Dockerfile.build-"$DOCKER_DIST"-i386-cross
3434
fi
3535

36-
docker build -t "$IMAGE" -f "$DOCKERFILE" .
36+
# speed up build by pulling last built image from quay.io and building the docker file using the old image as a base
37+
docker pull "$IMAGE" || true
38+
# if the image hasn't changed, this should be a no-op
39+
IMAGE="$IMAGE":latest
40+
docker build --cache-from "$IMAGE" -t "$IMAGE" -f "$DOCKERFILE" .
3741

3842
if [[ "$BUILD_LITE" == "" ]]; then
3943
build_script=travis-build.sh
@@ -49,3 +53,10 @@ fi
4953

5054
docker run -e ARCH -e TRAVIS_BUILD_NUMBER --rm -it "${DOCKER_OPTS[@]}" -v $(readlink -f ..):/ws "$IMAGE" \
5155
bash -xc "export CI=1 && export DEBIAN_DIST=\"$DOCKER_DIST\" && cd /ws && source travis/$build_script"
56+
57+
# push built image as cache for future builds to registry
58+
# credentials shall only be available on (protected) master branch
59+
if [[ "$DOCKER_USERNAME" != "" ]]; then
60+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin quay.io
61+
docker push "$IMAGE"
62+
fi

0 commit comments

Comments
 (0)