convert docker build to using remote tagging logic

refs DE-432

[build-registry-path=jenkins/canvas-lms-de-432]
[change-merged]

Change-Id: I1691d0a729abfd304eaad11a9e8aa0cc05874ac8
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/257003
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Kyle Rosenbaum <krosenbaum@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Product-Review: Aaron Ogata <aogata@instructure.com>
This commit is contained in:
Aaron Ogata 2021-01-19 14:00:04 -08:00
parent 812eae65b6
commit df7bd93b75
3 changed files with 12 additions and 20 deletions

18
Jenkinsfile vendored
View File

@ -438,6 +438,8 @@ pipeline {
pluginsToPull.add([name: 'qti_migration_tool', version: getPluginVersion('qti_migration_tool'), target: "vendor/qti_migration_tool"])
pullRepos(pluginsToPull)
libraryScript.load('bash/docker-tag-remote.sh', './build/new-jenkins/docker-tag-remote.sh')
}
}
@ -477,7 +479,9 @@ pipeline {
"WEBPACK_CACHE_PREFIX=${env.WEBPACK_CACHE_PREFIX}",
"YARN_RUNNER_PREFIX=${env.YARN_RUNNER_PREFIX}",
]) {
sh "build/new-jenkins/docker-build.sh $PATCHSET_TAG"
credentials.withStarlordCredentials({ ->
sh "build/new-jenkins/docker-build.sh $PATCHSET_TAG"
})
}
}
}
@ -498,16 +502,6 @@ pipeline {
./build/new-jenkins/docker-with-flakey-network-protection.sh push $WEBPACK_CACHE_PREFIX
""", label: 'upload cache images')
def hasWebpackBuilderImage = sh(script: "./build/new-jenkins/docker-with-flakey-network-protection.sh push $WEBPACK_BUILDER_IMAGE", returnStatus: true)
// If we are unable to push up the webpack builder image, then this
// build should use the currently cached image.
if (hasWebpackBuilderImage != 0) {
def webpackBuilderLabel = sh(script: "docker inspect $PATCHSET_TAG --format '{{ .Config.Labels.WEBPACK_BUILDER_SELECTED_TAG }}'", returnStdout: true).trim()
dockerUtils.tagRemote(webpackBuilderLabel, env.WEBPACK_BUILDER_IMAGE)
}
if (isPatchsetPublishable()) {
sh 'docker tag $PATCHSET_TAG $EXTERNAL_TAG'
sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $EXTERNAL_TAG'
@ -520,8 +514,6 @@ pipeline {
def cacheLoadScope = configuration.isChangeMerged() || configuration.getBoolean('skip-cache') ? '' : env.IMAGE_CACHE_MERGE_SCOPE
def cacheSaveScope = configuration.isChangeMerged() ? env.IMAGE_CACHE_MERGE_SCOPE : ''
libraryScript.load('bash/docker-tag-remote.sh', './build/new-jenkins/docker-tag-remote.sh')
withEnv([
"CACHE_LOAD_SCOPE=${cacheLoadScope}",
"CACHE_SAVE_SCOPE=${cacheSaveScope}",

View File

@ -93,11 +93,6 @@ docker image inspect starlord.inscloudgate.net/jenkins/canvas-lms:20.255220.11-p
}
```
The build currently relies on the post-merge build re-building webpack due to $JS_BUILD_NO_UGLIFY being different for
pre-merge builds. If this changes, the post-merge build will start to share images with the pre-merge build, and this
will lead to the ruby-runner / yarn-runner / webpack-builder images not being transferred correctly to the post-merge
scope. This can be fixed by using the `dockerUtils.tagRemote()` pattern for ruby-runner / yarn-runner / webpack-builder.
# FAQ
Q: I added a new file dependency to `bundle exec rake canvas:compile_assets` or similar task, and

View File

@ -139,7 +139,6 @@ if [ -z "${WEBPACK_CACHE_SELECTED_TAG}" ]; then
--label "RUBY_RUNNER_SELECTED_TAG=$RUBY_RUNNER_SELECTED_TAG" \
--label "YARN_RUNNER_SELECTED_TAG=$YARN_RUNNER_SELECTED_TAG" \
--tag "${WEBPACK_BUILDER_TAGS[SAVE_TAG]}" \
${WEBPACK_BUILDER_TAGS["UNIQUE_TAG"]:+ --tag "${WEBPACK_BUILDER_TAGS["UNIQUE_TAG"]}"} \
- < Dockerfile.jenkins.webpack-builder
WEBPACK_BUILDER_SELECTED_TAG=${WEBPACK_BUILDER_TAGS[SAVE_TAG]}
@ -158,7 +157,7 @@ if [ -z "${WEBPACK_CACHE_SELECTED_TAG}" ]; then
tag_many $RUBY_RUNNER_SELECTED_TAG local/ruby-runner ${RUBY_RUNNER_TAGS[SAVE_TAG]}
fi
tag_many $WEBPACK_BUILDER_SELECTED_TAG local/webpack-builder ${WEBPACK_BUILDER_TAGS[SAVE_TAG]}
tag_many $WEBPACK_BUILDER_SELECTED_TAG local/webpack-builder ${WEBPACK_BUILDER_TAGS[SAVE_TAG]} ${WEBPACK_BUILDER_TAGS[UNIQUE_TAG]-}
# Using a multi-stage build is safe for the below image because
# there is no expectation that we will need to use docker's
@ -179,6 +178,12 @@ else
RUBY_RUNNER_SELECTED_TAG=$(docker inspect $WEBPACK_CACHE_SELECTED_TAG --format '{{ .Config.Labels.RUBY_RUNNER_SELECTED_TAG }}')
YARN_RUNNER_SELECTED_TAG=$(docker inspect $WEBPACK_CACHE_SELECTED_TAG --format '{{ .Config.Labels.YARN_RUNNER_SELECTED_TAG }}')
WEBPACK_BUILDER_SELECTED_TAG=$(docker inspect $WEBPACK_CACHE_SELECTED_TAG --format '{{ .Config.Labels.WEBPACK_BUILDER_SELECTED_TAG }}')
[ "$RUBY_RUNNER_SELECTED_TAG" != "${RUBY_RUNNER_TAGS[SAVE_TAG]}" ] && tag_remote_async "RUBY_RUNNER_TAG_REMOTE_SAVE_PID" $RUBY_RUNNER_SELECTED_TAG ${RUBY_RUNNER_TAGS[SAVE_TAG]}
[ "$YARN_RUNNER_SELECTED_TAG" != "${YARN_RUNNER_TAGS[SAVE_TAG]}" ] && tag_remote_async "YARN_RUNNER_TAG_REMOTE_SAVE_PID" $YARN_RUNNER_SELECTED_TAG ${YARN_RUNNER_TAGS[SAVE_TAG]}
[ "$WEBPACK_BUILDER_SELECTED_TAG" != "${WEBPACK_BUILDER_TAGS[SAVE_TAG]}" ] && tag_remote_async "WEBPACK_BUILDER_TAG_REMOTE_SAVE_PID" $WEBPACK_BUILDER_SELECTED_TAG ${WEBPACK_BUILDER_TAGS[SAVE_TAG]}
[ ! -z "${CACHE_UNIQUE_SCOPE-}" ] && tag_remote_async "WEBPACK_BUILDER_TAG_REMOTE_UNIQUE_PID" $WEBPACK_BUILDER_SELECTED_TAG ${WEBPACK_BUILDER_TAGS[UNIQUE_TAG]}
fi
tag_many $WEBPACK_CACHE_SELECTED_TAG local/webpack-cache ${WEBPACK_CACHE_TAGS[SAVE_TAG]}