add image dependencies as metadata

refs DE-402

In order to improve image debugging, store the tag of the dependency image as a label. This also allows us to tag those layers on each rspec / selenium node for free, preventing future builds that run on the node from having to download them again.

Change-Id: Ib36ad11463f98e03a3692c9ded80290e638df11a
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/254289
Reviewed-by: Kyle Rosenbaum <krosenbaum@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Product-Review: Aaron Ogata <aogata@instructure.com>
This commit is contained in:
Aaron Ogata 2020-12-04 08:49:02 -08:00
parent 4540d77073
commit 8dddd036af
2 changed files with 25 additions and 16 deletions

View File

@ -63,15 +63,21 @@ WEBPACK_CACHE_ID=$(echo "$BASE_IMAGE_ID $DOCKERFILE_CACHE_MD5 $YARN_CACHE_MD5 $P
WEBPACK_CACHE_SAVE_TAG="$WEBPACK_CACHE_PREFIX:$WEBPACK_CACHE_SAVE_SCOPE-$WEBPACK_CACHE_ID"
WEBPACK_CACHE_LOAD_TAG="$WEBPACK_CACHE_PREFIX:${WEBPACK_CACHE_LOAD_SCOPE:-$WEBPACK_CACHE_SAVE_SCOPE}-$WEBPACK_CACHE_ID"
# Check first if the primary cache ($WEBPACK_CACHE_LOAD_TAG) exists for these files
# Fallback to the secondary cache ($WEBPACK_CACHE_SAVE_TAG).
exit_code=0
(./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_CACHE_LOAD_TAG && docker tag $WEBPACK_CACHE_LOAD_TAG local/webpack-cache) \
|| (./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_CACHE_SAVE_TAG && docker tag $WEBPACK_CACHE_SAVE_TAG local/webpack-cache) \
|| exit_code=$?
# Build / Load Webpack Image
WEBPACK_CACHE_SELECTED_TAG=""
# If any webpack-related file has changed, we need to pull $WEBPACK_BUILDER_CACHE_TAG and rebuild.
if [[ "$exit_code" != "0" ]]; then
if ./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_CACHE_LOAD_TAG; then
# Optimize for changes that don't require webpack to re-build. Pull the image that is shared
# across all patchsets.
WEBPACK_CACHE_SELECTED_TAG=$WEBPACK_CACHE_LOAD_TAG
docker tag $WEBPACK_CACHE_SELECTED_TAG local/webpack-cache
elif ./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_CACHE_SAVE_TAG; then
WEBPACK_CACHE_SELECTED_TAG=$WEBPACK_CACHE_SAVE_TAG
docker tag $WEBPACK_CACHE_SELECTED_TAG local/webpack-cache
else
# If any webpack-related file has changed, we need to pull $WEBPACK_BUILDER_CACHE_TAG and rebuild.
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_BUILDER_CACHE_TAG || true
docker build \
@ -90,12 +96,16 @@ if [[ "$exit_code" != "0" ]]; then
--tag "local/webpack-cache" \
--tag "$WEBPACK_CACHE_SAVE_TAG" \
- < Dockerfile.jenkins.webpack-cache
WEBPACK_CACHE_SELECTED_TAG=$WEBPACK_CACHE_SAVE_TAG
fi
# Build Final Image
if [ -n "${1:-}" ]; then
docker build \
--build-arg COMPILE_ADDITIONAL_ASSETS="$COMPILE_ADDITIONAL_ASSETS" \
--file Dockerfile.jenkins.final \
--label "WEBPACK_CACHE_SELECTED_TAG=$WEBPACK_CACHE_SELECTED_TAG" \
--tag "$1" \
"$WORKSPACE"
fi

View File

@ -7,17 +7,16 @@ set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
REGISTRY_BASE=starlord.inscloudgate.net/jenkins
POSTGIS=${POSTGIS:-2.5}
# canvas-lms
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $PATCHSET_TAG
# redis
# When this build finishes, the docker clean-up script will remove the $PATCHSET_TAG
# because it is unlikely that another build that runs on the node will need it, saving
# disk space. The dependency image(s) will not be cleared however, so tag them to avoid
# future builds on this node from downloading the layers again.
WEBPACK_CACHE_SELECTED_TAG=$(docker image inspect -f "{{.Config.Labels.WEBPACK_CACHE_SELECTED_TAG}}" $PATCHSET_TAG)
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $WEBPACK_CACHE_SELECTED_TAG
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $REGISTRY_BASE/redis:alpine
# postgres database with postgis preinstalled
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $POSTGRES_IMAGE_TAG
# cassandra:2:2
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $CASSANDRA_IMAGE_TAG
# dynamodb-local
./build/new-jenkins/docker-with-flakey-network-protection.sh pull $DYNAMODB_IMAGE_TAG