diff --git a/Dockerfile b/Dockerfile index 7581a8785f2..fbb40c03aeb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,12 @@ ARG RUBY=2.6 -FROM instructure/passenger-nginx-alpine:${RUBY} AS ruby-gems-only +FROM instructure/passenger-nginx-alpine:${RUBY} AS dependencies LABEL maintainer="Instructure" ARG POSTGRES_CLIENT=12.2 ARG ALPINE_MIRROR=http://dl-cdn.alpinelinux.org/alpine +ARG NODE=10.19.0-r0 ENV APP_HOME /usr/src/app/ ENV RAILS_ENV production @@ -96,16 +97,6 @@ RUN set -eux; \ && bundle install --jobs $(nproc) \ && rm -rf $GEM_HOME/cache -FROM ruby-gems-only AS ruby-final -COPY --chown=docker:docker . $APP_HOME - -FROM ruby-gems-only AS yarn-only -LABEL maintainer="Instructure" - -# default alpine HTTPS mirror -ARG ALPINE_MIRROR=https://alpine.global.ssl.fastly.net/alpine/ -ARG NODE=10.19.0-r0 - USER root RUN set -eux; \ \ @@ -178,7 +169,7 @@ RUN set -eux; \ && (yarn install --pure-lockfile || yarn install --pure-lockfile --network-concurrency 1) \ && yarn cache clean -FROM yarn-only AS webpack-final +FROM dependencies AS webpack-final ARG JS_BUILD_NO_UGLIFY=0 COPY --chown=docker:docker . ${APP_HOME} diff --git a/Jenkinsfile b/Jenkinsfile index 8ccbfd12935..8123db51eae 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -172,17 +172,10 @@ pipeline { ALPINE_MIRROR = configuration.alpineMirror() NODE = configuration.node() RUBY = configuration.ruby() // RUBY_VERSION is a reserved keyword for ruby installs - RUBY_IMAGE = "$BUILD_IMAGE-ruby" - RUBY_MERGE_IMAGE = "$RUBY_IMAGE:$GERRIT_BRANCH" - RUBY_PATCHSET_IMAGE = "$RUBY_IMAGE:$NAME-$TAG_SUFFIX" - RUBY_GEMS_IMAGE = "$BUILD_IMAGE-ruby-gems-only" - RUBY_GEMS_MERGE_IMAGE = "$RUBY_GEMS_IMAGE:$GERRIT_BRANCH" - RUBY_GEMS_PATCHSET_IMAGE = "$RUBY_GEMS_IMAGE:$NAME-$TAG_SUFFIX" - - YARN_IMAGE = "$BUILD_IMAGE-yarn-only" - YARN_MERGE_IMAGE = "$YARN_IMAGE:$GERRIT_BRANCH" - YARN_PATCHSET_IMAGE = "$YARN_IMAGE:$NAME-$TAG_SUFFIX" + DEPENDENCIES_IMAGE = "$BUILD_IMAGE-dependencies" + DEPENDENCIES_MERGE_IMAGE = "$DEPENDENCIES_IMAGE:$GERRIT_BRANCH" + DEPENDENCIES_PATCHSET_IMAGE = "$DEPENDENCIES_IMAGE:$NAME-$TAG_SUFFIX" CASSANDRA_IMAGE_TAG=imageTag.cassandra() DYNAMODB_IMAGE_TAG=imageTag.dynamodb() @@ -296,9 +289,7 @@ pipeline { ]) { sh 'build/new-jenkins/docker-build.sh' } - sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push $RUBY_GEMS_PATCHSET_IMAGE" - sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push $RUBY_PATCHSET_IMAGE" - sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push $YARN_PATCHSET_IMAGE" + sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push $DEPENDENCIES_PATCHSET_IMAGE" } sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push $PATCHSET_TAG" if (isPatchsetPublishable()) { @@ -432,16 +423,8 @@ pipeline { // Retriggers won't have an image to tag/push, pull that // image if doesn't exist. If image is not found it will // return NULL - if (!sh (script: 'docker images -q $RUBY_GEMS_PATCHSET_IMAGE')) { - sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $RUBY_GEMS_PATCHSET_IMAGE' - } - - if (!sh (script: 'docker images -q $RUBY_PATCHSET_IMAGE')) { - sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $RUBY_PATCHSET_IMAGE' - } - - if (!sh (script: 'docker images -q $YARN_PATCHSET_IMAGE')) { - sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $YARN_PATCHSET_IMAGE' + if (!sh (script: 'docker images -q $DEPENDENCIES_PATCHSET_IMAGE')) { + sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $DEPENDENCIES_PATCHSET_IMAGE' } if (!sh (script: 'docker images -q $PATCHSET_TAG')) { @@ -450,14 +433,10 @@ pipeline { // publish canvas-lms:$GERRIT_BRANCH (i.e. canvas-lms:master) sh 'docker tag $PUBLISHABLE_TAG $MERGE_TAG' - sh 'docker tag $RUBY_GEMS_PATCHSET_IMAGE $RUBY_GEMS_MERGE_IMAGE' - sh 'docker tag $RUBY_PATCHSET_IMAGE $RUBY_MERGE_IMAGE' - sh 'docker tag $YARN_PATCHSET_IMAGE $YARN_MERGE_IMAGE' + sh 'docker tag $DEPENDENCIES_PATCHSET_IMAGE $DEPENDENCIES_MERGE_IMAGE' // push *all* canvas-lms images (i.e. all canvas-lms prefixed tags) sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $MERGE_TAG' - sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $RUBY_GEMS_MERGE_IMAGE' - sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $RUBY_MERGE_IMAGE' - sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $YARN_MERGE_IMAGE' + sh './build/new-jenkins/docker-with-flakey-network-protection.sh push $DEPENDENCIES_MERGE_IMAGE' } } } diff --git a/build/Dockerfile.template b/build/Dockerfile.template index 124799610fe..9d590fd1ade 100644 --- a/build/Dockerfile.template +++ b/build/Dockerfile.template @@ -1,11 +1,12 @@ <%= generation_message %> ARG RUBY=2.6 -FROM instructure/passenger-nginx-alpine:${RUBY} AS ruby-gems-only +FROM instructure/passenger-nginx-alpine:${RUBY} AS dependencies LABEL maintainer="Instructure" ARG POSTGRES_CLIENT=12.2 ARG ALPINE_MIRROR=http://dl-cdn.alpinelinux.org/alpine +ARG NODE=10.19.0-r0 ENV APP_HOME /usr/src/app/ ENV RAILS_ENV production @@ -93,16 +94,6 @@ RUN set -eux; \ && bundle install --jobs $(nproc) \ && rm -rf $GEM_HOME/cache -FROM ruby-gems-only AS ruby-final -COPY --chown=docker:docker . $APP_HOME - -FROM ruby-gems-only AS yarn-only -LABEL maintainer="Instructure" - -# default alpine HTTPS mirror -ARG ALPINE_MIRROR=https://alpine.global.ssl.fastly.net/alpine/ -ARG NODE=10.19.0-r0 - USER root RUN set -eux; \ \ @@ -139,10 +130,12 @@ RUN set -eux; \ && (yarn install --pure-lockfile || yarn install --pure-lockfile --network-concurrency 1) \ && yarn cache clean -FROM yarn-only AS webpack-final +FROM dependencies AS webpack-final +ARG JS_BUILD_NO_UGLIFY=0 + COPY --chown=docker:docker . ${APP_HOME} RUN set -exu; \ \ - COMPILE_ASSETS_NPM_INSTALL=0 bundle exec rails canvas:compile_assets \ + COMPILE_ASSETS_NPM_INSTALL=0 JS_BUILD_NO_UGLIFY="$JS_BUILD_NO_UGLIFY" bundle exec rails canvas:compile_assets \ && yarn cache clean diff --git a/build/new-jenkins/docker-build.sh b/build/new-jenkins/docker-build.sh index dce786390ce..0cf56ddfe32 100755 --- a/build/new-jenkins/docker-build.sh +++ b/build/new-jenkins/docker-build.sh @@ -6,51 +6,30 @@ WORKSPACE=${WORKSPACE:-$(pwd)} RUBY_PATCHSET_IMAGE=${RUBY_PATCHSET_IMAGE:-canvas-lms-ruby} PATCHSET_TAG=${PATCHSET_TAG:-canvas-lms} -commonRubyArgs=( +dependencyArgs=( --build-arg ALPINE_MIRROR="$ALPINE_MIRROR" --build-arg BUILDKIT_INLINE_CACHE=1 + --build-arg NODE="$NODE" --build-arg POSTGRES_CLIENT="$POSTGRES_CLIENT" --build-arg RUBY="$RUBY" --file Dockerfile ) -commonNodeArgs=( - --build-arg NODE="$NODE" -) - if [[ "${SKIP_CACHE:-false}" = "false" ]]; then - commonRubyArgs+=("--cache-from $RUBY_GEMS_MERGE_IMAGE") - commonNodeArgs+=("--cache-from $YARN_MERGE_IMAGE") + dependencyArgs+=("--cache-from $DEPENDENCIES_MERGE_IMAGE") fi # shellcheck disable=SC2086 DOCKER_BUILDKIT=1 docker build \ --pull \ - ${commonRubyArgs[@]} \ - --tag "$RUBY_GEMS_PATCHSET_IMAGE" \ - --target ruby-gems-only \ + ${dependencyArgs[@]} \ + --tag "$DEPENDENCIES_PATCHSET_IMAGE" \ + --target dependencies \ "$WORKSPACE" # shellcheck disable=SC2086 DOCKER_BUILDKIT=1 docker build \ - --pull \ - ${commonRubyArgs[@]} \ - --tag "$RUBY_PATCHSET_IMAGE" \ - --target ruby-final \ - "$WORKSPACE" - -# shellcheck disable=SC2086 -DOCKER_BUILDKIT=1 docker build \ - ${commonRubyArgs[@]} \ - ${commonNodeArgs[@]} \ - --tag "$YARN_PATCHSET_IMAGE" \ - --target yarn-only \ - "$WORKSPACE" - -# shellcheck disable=SC2086 -DOCKER_BUILDKIT=1 docker build \ - ${commonRubyArgs[@]} \ - ${commonNodeArgs[@]} \ + ${dependencyArgs[@]} \ --build-arg JS_BUILD_NO_UGLIFY="$JS_BUILD_NO_UGLIFY" \ --tag "$PATCHSET_TAG" \ --target webpack-final \