Skip to content

Commit

Permalink
Prepare final changes for bazel remote cache in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders committed May 3, 2022
1 parent a63ba24 commit 3d8d112
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
18 changes: 9 additions & 9 deletions .buildkite/pipelines/pull_request/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ steps:

# - wait

# - command: .buildkite/scripts/steps/bazel_cache/test.sh
# label: Bootstrap with disk cache
# timeout_in_minutes: 20
# parallelism: 100
# agents:
# queue: n2-4-spot

- command: .buildkite/scripts/steps/bazel_cache/test_clean.sh
label: Bootstrap with no disk cache
- command: .buildkite/scripts/steps/bazel_cache/test.sh
label: Bootstrap with disk cache
timeout_in_minutes: 20
parallelism: 100
agents:
queue: n2-4-spot

# - command: .buildkite/scripts/steps/bazel_cache/test_clean.sh
# label: Bootstrap with no disk cache
# timeout_in_minutes: 20
# parallelism: 100
# agents:
# queue: n2-4-spot
15 changes: 0 additions & 15 deletions .buildkite/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@ set -euo pipefail
source .buildkite/scripts/common/util.sh
source .buildkite/scripts/common/setup_bazel.sh

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"

cat << EOF > .bazelrc
import %workspace%/.bazelrc.common
build --remote_cache=https://storage.googleapis.com/$BAZEL_BUCKET
build --google_default_credentials
EOF

echo "--- yarn install and bootstrap"
echo "Using Bazel remote cache bucket: $BAZEL_BUCKET"

if ! yarn kbn bootstrap; then
echo "bootstrap failed, trying again in 15 seconds"
Expand Down
36 changes: 25 additions & 11 deletions .buildkite/scripts/common/setup_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,29 @@ cat <<EOF > $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 <<EOF >> $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 <<EOF >> $KIBANA_DIR/.bazelrc
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://remote.buildbuddy.io
Expand All @@ -22,14 +43,7 @@ cat <<EOF >> $KIBANA_DIR/.bazelrc
EOF
fi

if [[ "${BAZEL_CACHE_MODE:-none}" == "read" ]]; then
echo "[bazel] cache set to read-only"
cat <<EOF >> $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
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/bazel_cache/bootstrap_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/on_merge_ts_refs_api_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d8d112

Please sign in to comment.