Skip to content

Commit

Permalink
bazel: use GCS remote cache (envoyproxy#4050)
Browse files Browse the repository at this point in the history
Partially addresses envoyproxy#3741

Description:
Use GCS remote cache for CI builds when key is provided.

Risk Level: Low
Testing: CI
Docs Changes:
Release Notes:

Signed-off-by: Lizan Zhou <[email protected]>
  • Loading branch information
lizan authored and htuch committed Aug 12, 2018
1 parent 5fe4e14 commit 7309c14
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
- image: *envoy-build-image
resource_class: xlarge
working_directory: /source
environment:
BAZEL_REMOTE_CACHE: https://storage.googleapis.com/envoy-circleci-bazel-cache/
steps:
- run: rm -rf /home/circleci/project/.git # CircleCI git caching is likely broken
- checkout
Expand All @@ -21,6 +23,8 @@ jobs:
- image: *envoy-build-image
resource_class: xlarge
working_directory: /source
environment:
BAZEL_REMOTE_CACHE: https://storage.googleapis.com/envoy-circleci-bazel-cache/
steps:
- run: rm -rf /home/circleci/project/.git # CircleCI git caching is likely broken
- run: echo $CIRCLE_SHA1
Expand All @@ -33,6 +37,8 @@ jobs:
- image: *envoy-build-image
resource_class: xlarge
working_directory: /source
environment:
BAZEL_REMOTE_CACHE: https://storage.googleapis.com/envoy-circleci-bazel-cache/
steps:
- run: rm -rf /home/circleci/project/.git # CircleCI git caching is likely broken
- checkout
Expand Down Expand Up @@ -64,6 +70,8 @@ jobs:
- run: ci/filter_example_mirror.sh
ipv6_tests:
machine: true
environment:
BAZEL_REMOTE_CACHE: https://storage.googleapis.com/envoy-circleci-bazel-cache/
steps:
- run: rm -rf /home/circleci/project/.git # CircleCI git caching is likely broken
- checkout
Expand Down Expand Up @@ -136,6 +144,8 @@ jobs:
mac:
macos:
xcode: "9.3.0"
environment:
BAZEL_REMOTE_CACHE: https://storage.googleapis.com/envoy-circleci-bazel-cache/
steps:
- run: sudo ntpdate -vu time.apple.com
- run: rm -rf /home/circleci/project/.git # CircleCI git caching is likely broken
Expand Down
1 change: 1 addition & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [[ "$1" == "fix_format" || "$1" == "check_format" ]]; then
build_setup_args="-nofetch"
fi

. "$(dirname "$0")"/setup_gcs_cache.sh
. "$(dirname "$0")"/build_setup.sh $build_setup_args

echo "building using ${NUM_CPUS} CPUs"
Expand Down
1 change: 1 addition & 0 deletions ci/do_circle_ci_ipv6_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ echo "disk space at beginning of build:"
df -h

docker run -t -i -v "$ENVOY_BUILD_DIR":/build -v "$ENVOY_SRCDIR":/source \
--env GCP_SERVICE_ACCOUNT_KEY --env BAZEL_REMOTE_CACHE \
envoyproxy/envoy-build:"$ENVOY_BUILD_SHA" /bin/bash -c "cd /source && ci/do_ci.sh $TEST_TYPE"

4 changes: 3 additions & 1 deletion ci/mac_ci_steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -e

BAZEL_BUILD_OPTIONS="--curses=no --show_task_finish --verbose_failures"
. "$(dirname "$0")"/setup_gcs_cache.sh

BAZEL_BUILD_OPTIONS="--curses=no --show_task_finish --verbose_failures ${BAZEL_BUILD_EXTRA_OPTIONS}"
# TODO(zuercher): remove --flaky_test_attempts when https://github.com/envoyproxy/envoy/issues/2428
# is resolved.
BAZEL_TEST_OPTIONS="${BAZEL_BUILD_OPTIONS} --test_output=all --flaky_test_attempts=integration@2"
Expand Down
31 changes: 31 additions & 0 deletions ci/setup_gcs_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

if [[ ! -z "${BAZEL_REMOTE_CACHE}" ]]; then
if [[ ! -z "${GCP_SERVICE_ACCOUNT_KEY}" ]]; then
# mktemp will create a tempfile with u+rw permission minus umask, it will not be readable by all
# users by default.
GCP_SERVICE_ACCOUNT_KEY_FILE=$(mktemp -t gcp_service_account.XXXXXX.json)

gcp_service_account_cleanup() {
echo "Deleting service account key file..."
rm -rf "${GCP_SERVICE_ACCOUNT_KEY_FILE}"
}

trap gcp_service_account_cleanup EXIT

echo "${GCP_SERVICE_ACCOUNT_KEY}" | base64 --decode > "${GCP_SERVICE_ACCOUNT_KEY_FILE}"

export BAZEL_BUILD_EXTRA_OPTIONS="${BAZEL_BUILD_EXTRA_OPTIONS} \
--remote_http_cache=${BAZEL_REMOTE_CACHE} \
--google_credentials=${GCP_SERVICE_ACCOUNT_KEY_FILE}"
echo "Set up bazel read/write HTTP cache at ${BAZEL_REMOTE_CACHE}."
else
export BAZEL_BUILD_EXTRA_OPTIONS="${BAZEL_BUILD_EXTRA_OPTIONS} \
--remote_http_cache=${BAZEL_REMOTE_CACHE} --noremote_upload_local_results"
echo "Set up bazel read only HTTP cache at ${BAZEL_REMOTE_CACHE}."
fi
else
echo "No remote cache bucket is set, skipping setup remote cache."
fi

0 comments on commit 7309c14

Please sign in to comment.