From bd18048cb878f32af5ac960001340e7e8b5188b0 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Tue, 3 May 2022 16:49:37 -0400 Subject: [PATCH] [CI] Use GCS buckets for bazel remote caching (#131345) --- .buildkite/scripts/common/setup_bazel.sh | 36 +++++++++++++------ .../steps/bazel_cache/bootstrap_mac.sh | 2 +- .../steps/on_merge_ts_refs_api_docs.sh | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.buildkite/scripts/common/setup_bazel.sh b/.buildkite/scripts/common/setup_bazel.sh index 96cd04fa612fd..e3791dfa393c7 100755 --- a/.buildkite/scripts/common/setup_bazel.sh +++ b/.buildkite/scripts/common/setup_bazel.sh @@ -11,8 +11,29 @@ cat < $KIBANA_DIR/.bazelrc build --build_metadata=ROLE=CI EOF -if [[ "${BAZEL_CACHE_MODE:-none}" == read* ]]; then - echo "[bazel] enabling caching" +BAZEL_CACHE_MODE=${BAZEL_CACHE_MODE:-gcs} + +if [[ "$BAZEL_CACHE_MODE" == "gcs" ]]; then + echo "[bazel] enabling caching with GCS buckets" + + BAZEL_REGION="us-central1" + if [[ "$(curl -is metadata.google.internal || true)" ]]; then + # projects/1003139005402/zones/us-central1-a -> us-central1-a -> us-central1 + BAZEL_REGION=$(curl -sH Metadata-Flavor:Google http://metadata.google.internal/computeMetadata/v1/instance/zone | rev | cut -d'/' -f1 | cut -c3- | rev) + fi + + BAZEL_BUCKET="kibana-ci-bazel_$BAZEL_REGION" + + echo "[bazel] using GCS bucket: $BAZEL_BUCKET" + +cat <> $KIBANA_DIR/.bazelrc + build --remote_cache=https://storage.googleapis.com/$BAZEL_BUCKET + build --google_default_credentials +EOF +fi + +if [[ "$BAZEL_CACHE_MODE" == "buildbuddy" ]]; then + echo "[bazel] enabling caching with Buildbuddy" cat <> $KIBANA_DIR/.bazelrc build --bes_results_url=https://app.buildbuddy.io/invocation/ build --bes_backend=grpcs://remote.buildbuddy.io @@ -22,14 +43,7 @@ cat <> $KIBANA_DIR/.bazelrc EOF fi -if [[ "${BAZEL_CACHE_MODE:-none}" == "read" ]]; then - echo "[bazel] cache set to read-only" -cat <> $KIBANA_DIR/.bazelrc - build --noremote_upload_local_results -EOF -fi - -if [[ "${BAZEL_CACHE_MODE:-none}" != @(read|read-write|none|) ]]; then - echo "invalid value for BAZEL_CACHE_MODE received ($BAZEL_CACHE_MODE), expected one of [read,read-write,none]" +if [[ "$BAZEL_CACHE_MODE" != @(gcs|buildbuddy|none|) ]]; then + echo "invalid value for BAZEL_CACHE_MODE received ($BAZEL_CACHE_MODE), expected one of [gcs,buildbuddy,none]" exit 1 fi diff --git a/.buildkite/scripts/steps/bazel_cache/bootstrap_mac.sh b/.buildkite/scripts/steps/bazel_cache/bootstrap_mac.sh index 1417137f0b6f0..62aabf496fd8a 100755 --- a/.buildkite/scripts/steps/bazel_cache/bootstrap_mac.sh +++ b/.buildkite/scripts/steps/bazel_cache/bootstrap_mac.sh @@ -2,7 +2,7 @@ set -euo pipefail -export BAZEL_CACHE_MODE=read-write +export BAZEL_CACHE_MODE=buildbuddy export DISABLE_BOOTSTRAP_VALIDATION=true # Since our Mac agents are currently static, diff --git a/.buildkite/scripts/steps/on_merge_ts_refs_api_docs.sh b/.buildkite/scripts/steps/on_merge_ts_refs_api_docs.sh index 6d08fbb2c6835..5659db50e1404 100755 --- a/.buildkite/scripts/steps/on_merge_ts_refs_api_docs.sh +++ b/.buildkite/scripts/steps/on_merge_ts_refs_api_docs.sh @@ -2,7 +2,7 @@ set -euo pipefail -export BAZEL_CACHE_MODE=read-write # Populate bazel remote cache for linux +export BAZEL_CACHE_MODE=buildbuddy # Populate Buildbuddy bazel remote cache for linux export BUILD_TS_REFS_CACHE_ENABLE=true export BUILD_TS_REFS_CACHE_CAPTURE=true export DISABLE_BOOTSTRAP_VALIDATION=true