remove buildkit for final Jenkins image

Buildkit seems to have a race condition where the cache is not used, or incompletely used, mostly on a new instance, but sometimes on an instance that has already used the cache successfully. We created a partial reproduction (g/250409) where with buildkit, layers above the modified layer were rebuilt, and with this change, all cached layers are correctly used.

[change-merged]
[build-registry-path=jenkins/canvas-lms/final-no-buildkit]

Change-Id: If10c186583cc21421d861bc2d1d43c7d2b0fc2f9
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/250400
Reviewed-by: James Butters <jbutters@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-10-19 07:08:40 -07:00
parent f31e2a59eb
commit 155402f15d
5 changed files with 44 additions and 83 deletions

View File

@ -1,37 +1,10 @@
# syntax = docker/dockerfile:1.0-experimental
# GENERATED FILE, DO NOT MODIFY!
# To update this file please edit the relevant template and run the generation
# task `build/dockerfile_writer.rb --env jenkins --compose-file docker-compose.yml,docker-compose.override.yml --in build/Dockerfile.template --out Dockerfile.jenkins`
ARG RUBY=2.6-p6.0.4
FROM busybox AS cache-helper-collect-gems
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -name "Gemfile" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.d" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.lock" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "*.gemspec" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "gem_version.rb" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "version.rb" -exec cp --parents {} /tmp/dst \;
FROM busybox AS cache-helper-collect-yarn
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems/canvas_i18nliner -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find packages/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find client_apps/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
FROM busybox AS cache-helper-collect-webpack
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -type d -not -path "gems/plugins/*" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/coffeescripts" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/jsx" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/views/jst" -exec cp -rf --parents {} /tmp/dst \;
FROM instructure/ruby-passenger:$RUBY AS webpack-final
FROM instructure/ruby-passenger:$RUBY
LABEL maintainer="Instructure"
ARG POSTGRES_CLIENT=12
@ -82,7 +55,7 @@ COPY --chown=docker:docker config/canvas_rails_switcher.rb ${APP_HOME}/config/ca
COPY --chown=docker:docker Gemfile ${APP_HOME}
COPY --chown=docker:docker Gemfile.d ${APP_HOME}Gemfile.d
COPY --chown=docker:docker --from=cache-helper-collect-gems /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-gems /tmp/dst ${APP_HOME}
RUN set -eux; \
\
@ -98,7 +71,7 @@ RUN set -eux; \
COPY --chown=docker:docker package.json ${APP_HOME}
COPY --chown=docker:docker yarn.lock ${APP_HOME}
COPY --chown=docker:docker --from=cache-helper-collect-yarn /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-yarn /tmp/dst ${APP_HOME}
RUN set -eux; \
mkdir -p .yardoc \
@ -156,7 +129,7 @@ COPY --chown=docker:docker client_apps ${APP_HOME}client_apps
COPY --chown=docker:docker config ${APP_HOME}config
COPY --chown=docker:docker db/migrate/*_regenerate_brand_files_based_on_new_defaults_*.rb ${APP_HOME}db/migrate/
COPY --chown=docker:docker frontend_build ${APP_HOME}frontend_build
COPY --chown=docker:docker --from=cache-helper-collect-webpack /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-webpack /tmp/dst ${APP_HOME}
COPY --chown=docker:docker lib ${APP_HOME}lib
COPY --chown=docker:docker public ${APP_HOME}public
COPY --chown=docker:docker Rakefile ${APP_HOME}

27
Dockerfile.jenkins-cache Normal file
View File

@ -0,0 +1,27 @@
# syntax = docker/dockerfile:1.0-experimental
FROM busybox AS cache-helper-collect-gems
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -name "Gemfile" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.d" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.lock" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "*.gemspec" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "gem_version.rb" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "version.rb" -exec cp --parents {} /tmp/dst \;
FROM busybox AS cache-helper-collect-yarn
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems/canvas_i18nliner -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find packages/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find client_apps/* -name 'package.json' -exec cp --parents {} /tmp/dst \;
FROM busybox AS cache-helper-collect-webpack
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -type d -not -path "gems/plugins/*" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/coffeescripts" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/jsx" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/views/jst" -exec cp -rf --parents {} /tmp/dst \;

View File

@ -1,35 +1,7 @@
<% if jenkins? -%>
# syntax = docker/dockerfile:1.0-experimental
<% end -%>
<%= generation_message %>
ARG RUBY=2.6-p6.0.4
<% if jenkins? -%>
FROM busybox AS cache-helper-collect-gems
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -name "Gemfile" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.d" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "Gemfile.lock" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "*.gemspec" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "gem_version.rb" -exec cp --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems -name "version.rb" -exec cp --parents {} /tmp/dst \;
FROM busybox AS cache-helper-collect-yarn
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
<%= yarn_packages.map { |p| "RUN --mount=target=/tmp/src find #{p} -name 'package.json' -exec cp --parents {} /tmp/dst \\;" }.join("\n") %>
FROM busybox AS cache-helper-collect-webpack
RUN mkdir -p /tmp/dst /tmp/dst
WORKDIR /tmp/src
RUN --mount=target=/tmp/src find gems -type d -not -path "gems/plugins/*" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/coffeescripts" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/jsx" -exec cp -rf --parents {} /tmp/dst \;
RUN --mount=target=/tmp/src find gems/plugins -path "app/views/jst" -exec cp -rf --parents {} /tmp/dst \;
<% end -%>
FROM instructure/ruby-passenger:$RUBY AS webpack-final
FROM instructure/ruby-passenger:$RUBY
LABEL maintainer="Instructure"
ARG POSTGRES_CLIENT=12
@ -81,7 +53,7 @@ COPY --chown=docker:docker Gemfile ${APP_HOME}
COPY --chown=docker:docker Gemfile.d ${APP_HOME}Gemfile.d
<% if jenkins? -%>
COPY --chown=docker:docker --from=cache-helper-collect-gems /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-gems /tmp/dst ${APP_HOME}
<% else -%>
COPY --chown=docker:docker gems ${APP_HOME}gems
<% end -%>
@ -101,7 +73,7 @@ COPY --chown=docker:docker package.json ${APP_HOME}
COPY --chown=docker:docker yarn.lock ${APP_HOME}
<% if jenkins? -%>
COPY --chown=docker:docker --from=cache-helper-collect-yarn /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-yarn /tmp/dst ${APP_HOME}
<% else -%>
COPY --chown=docker:docker client_apps ${APP_HOME}client_apps
COPY --chown=docker:docker packages ${APP_HOME}packages
@ -130,7 +102,7 @@ COPY --chown=docker:docker client_apps ${APP_HOME}client_apps
COPY --chown=docker:docker config ${APP_HOME}config
COPY --chown=docker:docker db/migrate/*_regenerate_brand_files_based_on_new_defaults_*.rb ${APP_HOME}db/migrate/
COPY --chown=docker:docker frontend_build ${APP_HOME}frontend_build
COPY --chown=docker:docker --from=cache-helper-collect-webpack /tmp/dst ${APP_HOME}
COPY --chown=docker:docker --from=local/cache-helper-collect-webpack /tmp/dst ${APP_HOME}
COPY --chown=docker:docker lib ${APP_HOME}lib
COPY --chown=docker:docker public ${APP_HOME}public
COPY --chown=docker:docker Rakefile ${APP_HOME}

View File

@ -4,28 +4,17 @@ set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
WORKSPACE=${WORKSPACE:-$(pwd)}
dependencyArgs=(
--build-arg BUILDKIT_INLINE_CACHE=1
--build-arg POSTGRES_CLIENT="$POSTGRES_CLIENT"
--build-arg RUBY="$RUBY"
--file Dockerfile.jenkins
)
echo "Cache manifest before building"
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $CACHE_TAG || true
DOCKER_BUILDKIT=1 docker build --file Dockerfile.jenkins-cache --tag "local/cache-helper-collect-gems" --target cache-helper-collect-gems "$WORKSPACE"
DOCKER_BUILDKIT=1 docker build --file Dockerfile.jenkins-cache --tag "local/cache-helper-collect-yarn" --target cache-helper-collect-yarn "$WORKSPACE"
DOCKER_BUILDKIT=1 docker build --file Dockerfile.jenkins-cache --tag "local/cache-helper-collect-webpack" --target cache-helper-collect-webpack "$WORKSPACE"
# shellcheck disable=SC2086
DOCKER_BUILDKIT=1 PROGRESS_NO_TRUNC=1 docker build \
--pull \
${dependencyArgs[@]} \
docker pull $CACHE_TAG || true
docker build \
--build-arg JS_BUILD_NO_UGLIFY="$JS_BUILD_NO_UGLIFY" \
--build-arg POSTGRES_CLIENT="$POSTGRES_CLIENT" \
--build-arg RUBY="$RUBY" \
--cache-from $CACHE_TAG \
--file Dockerfile.jenkins \
--tag "$1" \
--target webpack-final \
"$WORKSPACE"
echo "Cache manifest after building"
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $CACHE_TAG || true
echo "Built image"
docker image inspect $1

View File

@ -8,7 +8,7 @@ fileArr=(
'^build/common_docker_build_steps.sh'
'^script/canvas_update'
'^docker-compose.yml'
'^Dockerfile'
'^Dockerfile$'
'^lib/tasks/'
)