From 3837986d0d766398db97888a5eaaabf8d57b7238 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sat, 4 Jan 2025 15:33:19 +0000 Subject: [PATCH] cache log --- barretenberg/ts/bootstrap.sh | 6 ++---- boxes/bootstrap.sh | 6 +++--- ci.sh | 5 +++-- ci3/bootstrap_ec2 | 5 +++++ ci3/cache_log | 24 ++++++++++++++++++++++++ noir/bootstrap.sh | 3 ++- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100755 ci3/cache_log diff --git a/barretenberg/ts/bootstrap.sh b/barretenberg/ts/bootstrap.sh index 35c95d8c056..addf290c1e4 100755 --- a/barretenberg/ts/bootstrap.sh +++ b/barretenberg/ts/bootstrap.sh @@ -7,14 +7,12 @@ hash=$(cache_content_hash ../cpp/.rebuild_patterns .rebuild_patterns) function build { echo_header "bb.js build" + denoise "yarn install" + if ! cache_download bb.js-$hash.tar.gz; then - denoise "yarn install" find . -exec touch -d "@0" {} + 2>/dev/null || true - denoise "yarn build" cache_upload bb.js-$hash.tar.gz dest - else - denoise "yarn install" fi # We copy snapshot dirs to dest so we can run tests from dest. diff --git a/boxes/bootstrap.sh b/boxes/bootstrap.sh index 2463af9c66c..76857567f4f 100755 --- a/boxes/bootstrap.sh +++ b/boxes/bootstrap.sh @@ -17,11 +17,11 @@ hash=$(cache_content_hash \ function build { echo_header "boxes build" + denoise yarn + if ! cache_download boxes-$hash.tar.gz; then - denoise 'yarn && echo "Building... " && yarn build' + denoise 'yarn build' cache_upload boxes-$hash.tar.gz boxes/*/{artifacts,dist,src/contracts/target} - else - denoise yarn fi } diff --git a/ci.sh b/ci.sh index 6f657ea3cd5..34c1b5e8d9e 100755 --- a/ci.sh +++ b/ci.sh @@ -14,7 +14,8 @@ function echo_cmd { function print_usage { echo "usage: $(basename $0) " echo - echo_cmd "ec2" "Launch an ec2 instance and bootstrap on it. Exactly what Github action does, but doesn't touch GA." + echo_cmd "ec2" "Launch an ec2 instance and bootstrap on it." \ + "Exactly what Github Action's does, but doesn't touch GA." echo_cmd "local" "Clone your last commit into the ci container and bootstrap on local hardware." echo_cmd "trigger" "Trigger the GA workflow on the PR associated with the current branch." \ "Effectively the same as ec2, only the results will be tracked on your PR." @@ -88,7 +89,7 @@ case "$cmd" in ./bootstrap.sh ci ;; "trigger") - # Trigger workflow and drop through to start logging. + # Trigger workflow. # We use this label trick because triggering the workflow direct doesn't associate with the PR. pr_number=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number') if [ -z "$pr_number" ]; then diff --git a/ci3/bootstrap_ec2 b/ci3/bootstrap_ec2 index 7235f71efce..e94431c762d 100755 --- a/ci3/bootstrap_ec2 +++ b/ci3/bootstrap_ec2 @@ -55,6 +55,8 @@ if [ -t 0 ]; then ssh_args="-t" docker_args+=" -ti" shell_on_fail="|| exec zsh" +else + cache_log=" | cache_log ${LOG_ID:-}" fi # Use ~/.ssh/build_instance_key to ssh into our requested instance. @@ -71,10 +73,12 @@ fi # We provide the host user and group ids to the entrypoint script to ensure alignment. # We raise the default pid limit to 32k. ssh ${ssh_args:-} -F $ci3/aws/build_instance_ssh_config ubuntu@$ip " +{ echo "Loading CRS into tmpfs..." sudo mkdir /mnt/bb-crs sudo mount -t tmpfs -o size=3G tmpfs /mnt/bb-crs sudo cp -r \$HOME/.bb-crs/* /mnt/bb-crs + echo "Done in \$SECONDS seconds." echo "Starting devbox..." docker run --privileged ${docker_args:-} \ @@ -104,4 +108,5 @@ ssh ${ssh_args:-} -F $ci3/aws/build_instance_ssh_config ubuntu@$ip " git checkout FETCH_HEAD $cmd ${shell_on_fail:-} ' +} 2>&1 ${cache_log:-} " diff --git a/ci3/cache_log b/ci3/cache_log new file mode 100755 index 00000000000..08f1fe8c5e6 --- /dev/null +++ b/ci3/cache_log @@ -0,0 +1,24 @@ +#!/bin/bash +# Runs the given command. +# If a redis cache is available and we're not in a terminal, duplicate output into a cache log. +NO_CD=1 source $(git rev-parse --show-toplevel)/ci3/source + +if [ -n "$CI_REDIS" ] && [ ! -t 1 ]; then + key=${LOG_ID:-$(uuid)} + echo -e "Log id: ${yellow}$key${reset}" + tee >(redis-cli -h $CI_REDIS -x SETEX $key 604800 &>/dev/null) + echo -e "Log id: ${yellow}$key${reset}" +else + cat +fi + +# NO_CD=1 source $(git rev-parse --show-toplevel)/ci3/source + +# if [ -n "$CI_REDIS" ] && [ ! -t 1 ]; then +# key=$(uuid) +# echo -e "Executing: $1 (${yellow}$key${reset})" +# bash -c "$1" | tee >(redis-cli -h $CI_REDIS -x SETEX $key 604800 &>/dev/null) +# echo -e "Complete: $1 (${yellow}$key${reset})" +# else +# exec bash -c "$1" +# fi \ No newline at end of file diff --git a/noir/bootstrap.sh b/noir/bootstrap.sh index 36d9e27f4c6..98485affd24 100755 --- a/noir/bootstrap.sh +++ b/noir/bootstrap.sh @@ -36,9 +36,10 @@ function build_native { # Builds js packages. function build_packages { set -euo pipefail + if cache_download noir-packages-$hash.tar.gz; then cd noir-repo - yarn + yarn install return fi