Fix cache usage for builds

Change-type: patch
This commit is contained in:
Pagan Gazzard 2019-07-19 15:57:47 +01:00
parent 095ec0620f
commit 0ad5d8688c

View File

@ -58,21 +58,21 @@ NODE_CACHE_MASTER=balena/$ARCH-supervisor-node:master$DEBUG
NODE_BUILD_CACHE_MASTER=balena/$ARCH-supervisor-node:master-build$DEBUG NODE_BUILD_CACHE_MASTER=balena/$ARCH-supervisor-node:master-build$DEBUG
CACHE_FROM="" CACHE_FROM=""
function tryPullForCache() { function useCache() {
image=$1 image=$1
docker pull $image && { # Always add the cache because we can't do it from
CACHE_FROM="$CACHE_FROM --cache-from $image" # a subshell and specifying a missing image is fine
} || true CACHE_FROM="$CACHE_FROM --cache-from $image"
# Pull in parallel for speed
docker pull $image &
} }
# Attempt to pull images for cache useCache $TARGET_CACHE
# Only if the pull succeeds we add a --cache-from option useCache $TARGET_CACHE_MASTER
tryPullForCache $TARGET_CACHE & useCache $NODE_CACHE
tryPullForCache $TARGET_CACHE_MASTER & useCache $NODE_CACHE_MASTER
tryPullForCache $NODE_CACHE & useCache $NODE_BUILD_CACHE
tryPullForCache $NODE_CACHE_MASTER & useCache $NODE_BUILD_CACHE_MASTER
tryPullForCache $NODE_BUILD_CACHE &
tryPullForCache $NODE_BUILD_CACHE_MASTER &
wait wait
export DOCKER_BUILD_OPTIONS=${CACHE_FROM} export DOCKER_BUILD_OPTIONS=${CACHE_FROM}