Skip to content

Commit

Permalink
build(bazel): improve remote caching for AIO local deps build
Browse files Browse the repository at this point in the history
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:

bazelbuild/bazel#10075 (comment)
  • Loading branch information
kormide committed Dec 25, 2022
1 parent 27da733 commit 7645553
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 0 additions & 1 deletion aio/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion aio/scripts/local-workspace-status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)
15 changes: 11 additions & 4 deletions aio/tools/example-zipper/exampleZipper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
zip.append(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});
}

0 comments on commit 7645553

Please sign in to comment.