forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: enable rosetta cache for builds (aws#17336)
Avail ourselves of the new build cache feature in cdklabs/cdk-ops#1776. Adds two new things: **A persistently cached directory** The directory `$HOME/.s3buildcache` will be stored and restored in the S3 bucket, if configured. The build can assume that files it puts in there will be availble on the next build (and on the corresponding PR build). **Cache rosetta tablet** If there is a file in the persistent cache directory for Rosetta, pass it to `jsii-rosetta` as an input. Afterwards, store whatever tablet the build produced back into the cache directory. The latter will only impact the persistent cache if done on a build that is actually configured to store the cache back, which is only the main pipeline build. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
9 changed files
with
102 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# | ||
# If the environment variable S3_BUILD_CACHE is set, download and extract the | ||
# tarball it points to into the directory $HOME/.s3buildcache. | ||
# | ||
set -eu | ||
|
||
cachedir=$HOME/.s3buildcache | ||
mkdir -p $cachedir | ||
|
||
if [[ "${S3_BUILD_CACHE:-}" = "" ]]; then | ||
exit 0 | ||
fi | ||
|
||
echo "🧳 Build cache enabled: ${S3_BUILD_CACHE}" | ||
if ! aws s3 ls ${S3_BUILD_CACHE} > /dev/null; then | ||
echo "🧳⚠️ Cache not found." | ||
exit 0 | ||
fi | ||
|
||
if ! (cd $cachedir && aws s3 cp ${S3_BUILD_CACHE} - | tar xzv); then | ||
echo "🧳⚠️ Something went wrong fetching the cache. Continuing anyway." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# | ||
# If the environment variable S3_BUILD_CACHE is set, compress and upload the | ||
# contents of $HOME/.s3buildcache to it. | ||
# | ||
set -eu | ||
|
||
cachedir=$HOME/.s3buildcache | ||
mkdir -p $cachedir | ||
|
||
if [[ "${S3_BUILD_CACHE:-}" = "" ]]; then | ||
exit 0 | ||
fi | ||
|
||
echo "🧳 Storing build cache at: ${S3_BUILD_CACHE}" | ||
|
||
if ! (cd $cachedir && tar czv . | aws s3 cp - ${S3_BUILD_CACHE}); then | ||
echo "🧳⚠️ Something went wrong storing the cache." | ||
fi | ||
|
||
echo "🧳 Finished." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# | ||
# Run jsii-rosetta on all jsii packages, using the S3 build cache if available. | ||
# | ||
# Usage: run-rosetta [PKGSFILE] | ||
# | ||
# If you already have a file with a list of all the JSII package directories | ||
# in it, pass it as the first argument. Otherwise, this script will run | ||
# 'list-packages' to determine a list itself. | ||
set -eu | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
|
||
ROSETTA=${ROSETTA:-npx jsii-rosetta} | ||
|
||
if [[ "${1:-}" = "" ]]; then | ||
echo "Collecting package list..." >&2 | ||
TMPDIR=${TMPDIR:-$(dirname $(mktemp -u))} | ||
node $scriptdir/list-packages $TMPDIR/jsii.txt $TMPDIR/nonjsii.txt | ||
jsii_pkgs_file=$TMPDIR/jsii.txt | ||
else | ||
jsii_pkgs_file=$1 | ||
fi | ||
|
||
rosetta_cache_file=$HOME/.s3buildcache/rosetta-cache.tabl.json | ||
rosetta_cache_opts="" | ||
if [[ -f $rosetta_cache_file ]]; then | ||
rosetta_cache_opts="--cache-from ${rosetta_cache_file}" | ||
fi | ||
|
||
$ROSETTA \ | ||
--compile \ | ||
--output samples.tabl.json \ | ||
$rosetta_cache_opts \ | ||
--directory packages/decdk \ | ||
$(cat $jsii_pkgs_file) | ||
|
||
if [[ -d $(dirname $rosetta_cache_file) ]]; then | ||
# If the cache directory is available, copy the current tablet into it | ||
cp samples.tabl.json $rosetta_cache_file | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters