From 217b1f35de81f12fb24171fcfadce4d9843a35a2 Mon Sep 17 00:00:00 2001 From: Aaron Ogata Date: Fri, 24 Jul 2020 10:21:26 -0700 Subject: [PATCH] skip uglify js / source maps on pre-merge builds v2 refs DE-161 Test Plan: 1. Ensure that JS sourcemaps are skipped on pre-merge 1. Ensure that JS sourcemaps are run on post-merge 3. Ensure that Linters catch bundle size increase limits on pre-merge Change-Id: I59607d902b191169a0415fc7673cb3a3a06dba68 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/243619 Tested-by: Service Cloud Jenkins QA-Review: Aaron Ogata QA-Review: Alex Slaughter Product-Review: Aaron Ogata Reviewed-by: Alex Slaughter --- Dockerfile | 4 +++- Jenkinsfile | 6 +++++- build/new-jenkins/docker-build.sh | 1 + docker-compose.new-jenkins.consumer.yml | 1 + frontend_build/baseWebpackConfig.js | 4 ++-- lib/tasks/canvas.rake | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 75deb940e76..7581a8785f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -179,9 +179,11 @@ RUN set -eux; \ && yarn cache clean FROM yarn-only 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/Jenkinsfile b/Jenkinsfile index a28ac9563f6..bfeb70d1755 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -288,7 +288,11 @@ pipeline { sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $MERGE_TAG' sh 'docker tag $MERGE_TAG $PATCHSET_TAG' } else { - sh 'build/new-jenkins/docker-build.sh' + withEnv([ + "JS_BUILD_NO_UGLIFY=${configuration.isChangeMerged() ? 0 : 1}" + ]) { + 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" diff --git a/build/new-jenkins/docker-build.sh b/build/new-jenkins/docker-build.sh index 3dad37cf4c4..dce786390ce 100755 --- a/build/new-jenkins/docker-build.sh +++ b/build/new-jenkins/docker-build.sh @@ -51,6 +51,7 @@ DOCKER_BUILDKIT=1 docker build \ DOCKER_BUILDKIT=1 docker build \ ${commonRubyArgs[@]} \ ${commonNodeArgs[@]} \ + --build-arg JS_BUILD_NO_UGLIFY="$JS_BUILD_NO_UGLIFY" \ --tag "$PATCHSET_TAG" \ --target webpack-final \ "$WORKSPACE" diff --git a/docker-compose.new-jenkins.consumer.yml b/docker-compose.new-jenkins.consumer.yml index 890ad85b2de..72aa84c8e22 100644 --- a/docker-compose.new-jenkins.consumer.yml +++ b/docker-compose.new-jenkins.consumer.yml @@ -7,6 +7,7 @@ services: - redis environment: RAILS_ENV: development + USE_OPTIMIZED_JS: "true" ports: - "8181:80" init: true diff --git a/frontend_build/baseWebpackConfig.js b/frontend_build/baseWebpackConfig.js index 9b8d5432ad3..7e9ce548d14 100644 --- a/frontend_build/baseWebpackConfig.js +++ b/frontend_build/baseWebpackConfig.js @@ -46,13 +46,13 @@ require('./bundles') // after-uglify size of things, but can skip making sourcemaps if you want it to // go faster. So this is to allow people to use either environment variable: // the technically more correct SKIP_SOURCEMAPS one or the historically used JS_BUILD_NO_UGLIFY one. -const skipSourcemaps = Boolean(process.env.SKIP_SOURCEMAPS || process.env.JS_BUILD_NO_UGLIFY) +const skipSourcemaps = Boolean(process.env.SKIP_SOURCEMAPS || process.env.JS_BUILD_NO_UGLIFY === '1') const root = path.resolve(__dirname, '..') module.exports = { mode: process.env.NODE_ENV, - performance: { + performance: skipSourcemaps ? false : { // This just reflects how big the 'main' entry is at the time of writing. Every // time we get it smaller we should change this to the new smaller number so it // only goes down over time instead of growing bigger over time diff --git a/lib/tasks/canvas.rake b/lib/tasks/canvas.rake index 3836c5c7781..c15c8a1774d 100644 --- a/lib/tasks/canvas.rake +++ b/lib/tasks/canvas.rake @@ -58,7 +58,7 @@ namespace :canvas do # build dev bundles even in prod mode so you can debug with ?optimized_js=0 query string # (except for on jenkins where we set JS_BUILD_NO_UGLIFY anyway so there's no need for an unminified fallback) build_prod = ENV['RAILS_ENV'] == 'production' || ENV['USE_OPTIMIZED_JS'] == 'true' || ENV['USE_OPTIMIZED_JS'] == 'True' - dont_need_dev_fallback = build_prod && ENV['JS_BUILD_NO_UGLIFY'] + dont_need_dev_fallback = build_prod && ENV['JS_BUILD_NO_UGLIFY'] == "1" build_tasks << 'js:webpack_development' unless dont_need_dev_fallback build_tasks << 'js:webpack_production' if build_prod end