From dd13eb3950ba3d6ce645d50fb4bc50739df6444c Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Sun, 25 Dec 2022 14:57:43 -0600 Subject: [PATCH] build(bazel): improve remote caching for AIO local deps build Fix non-hermetic zipping of example zips by fixing the zip entry timestamps. I also hardcoded stamp values in stable-status.txt and volatile-status.txt using the workspace status command for the aio_local_deps config to improve cache performance. The Bazel remote cache appears to not ignore volatile-status.txt when there are no other changes, unlike the local Bazel cache: https://github.com/bazelbuild/bazel/issues/10075#issuecomment-546872111 --- aio/BUILD.bazel | 1 - aio/scripts/local-workspace-status.mjs | 15 ++++++++++++++- aio/tools/example-zipper/exampleZipper.mjs | 15 +++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/aio/BUILD.bazel b/aio/BUILD.bazel index 523422f601e8ee..1690c3050523c8 100644 --- a/aio/BUILD.bazel +++ b/aio/BUILD.bazel @@ -125,7 +125,6 @@ copy_to_directory( # All source and configuration files required to build the docs app APPLICATION_FILES = [ "angular.json", - "package.json", "tsconfig.app.json", "tsconfig.json", "tsconfig.worker.json", diff --git a/aio/scripts/local-workspace-status.mjs b/aio/scripts/local-workspace-status.mjs index 29f375960d31c9..8c684433a53802 100644 --- a/aio/scripts/local-workspace-status.mjs +++ b/aio/scripts/local-workspace-status.mjs @@ -16,7 +16,20 @@ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')); const aioAngularVersion = pkgJson.dependencies['@angular/core'].replace(/^[\^~]/, '') + "+forAIOLocalBuildToAvoidMismatch"; -// Output the workspace status variable format to stdout so Bazel can read it console.log(`\ BUILD_SCM_VERSION ${aioAngularVersion} `); + +// Fix stable-status.txt values to improve remote cache performance. +console.log(`\ +BUILD_HOST fake_host +BUILD_USER fake_user +`) + +// Fix the timestamp in volatile-status.txt to improve remote cache performance. +// Unlike the local Bazel cache, the remote cache does not ignore volatile-status.txt +// and will invalidate actions that depend on it when the values change. +// https://github.com/bazelbuild/bazel/issues/10075#issuecomment-546872111 +console.log(`\ +BUILD_TIMESTAMP 0 +`) diff --git a/aio/tools/example-zipper/exampleZipper.mjs b/aio/tools/example-zipper/exampleZipper.mjs index a66a2c59fea637..7839a754e8aadb 100644 --- a/aio/tools/example-zipper/exampleZipper.mjs +++ b/aio/tools/example-zipper/exampleZipper.mjs @@ -182,18 +182,25 @@ export class ExampleZipper { // zip.append(fs.createReadStream(fileName), { name: relativePath }); let output = regionExtractor()(content, extn).contents; - zip.append(output, { name: relativePath } ); + appendToZip(zip, output, { name: relativePath, date: "0"}); }); // also a systemjs config if (exampleType === 'systemjs') { - zip.append(fs.readFileSync(this.examplesSystemjsConfig, 'utf8'), { name: 'src/systemjs.config.js' }); - zip.append(fs.readFileSync(this.examplesSystemjsLoaderConfig, 'utf8'), { name: 'src/systemjs-angular-loader.js' }); + appendToZip(zip, fs.readFileSync(this.examplesSystemjsConfig, 'utf8'), { name: 'src/systemjs.config.js' }); + appendToZip(zip, fs.readFileSync(this.examplesSystemjsLoaderConfig, 'utf8'), { name: 'src/systemjs-angular-loader.js' }); // a modified tsconfig let tsconfig = fs.readFileSync(this.exampleTsconfig, 'utf8'); - zip.append(this._changeTypeRoots(tsconfig), {name: 'src/tsconfig.json'}); + appendToZip(zip, this._changeTypeRoots(tsconfig), {name: 'src/tsconfig.json' }); } zip.finalize(); } } + +// Fix the timestamp on zip entries in order create reproducible zip +// files, which improves remote Bazel cache performance. +function appendToZip(zip, source, data) { + const FIXED_DATE = new Date(0); + zip.append(source, {...data, date: FIXED_DATE}); +}