From 7309c14cfebf9b285c0e5669a1195b9359609052 Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Sat, 11 Aug 2018 18:22:15 -0700 Subject: [PATCH] bazel: use GCS remote cache (#4050) Partially addresses #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 --- .circleci/config.yml | 10 ++++++++++ ci/do_ci.sh | 1 + ci/do_circle_ci_ipv6_tests.sh | 1 + ci/mac_ci_steps.sh | 4 +++- ci/setup_gcs_cache.sh | 31 +++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 ci/setup_gcs_cache.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 5abbabeff266..64cc32f9c251 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/ci/do_ci.sh b/ci/do_ci.sh index c7a164178875..a3bbc7598cec 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -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" diff --git a/ci/do_circle_ci_ipv6_tests.sh b/ci/do_circle_ci_ipv6_tests.sh index a265160037c6..fb0849924e50 100755 --- a/ci/do_circle_ci_ipv6_tests.sh +++ b/ci/do_circle_ci_ipv6_tests.sh @@ -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" diff --git a/ci/mac_ci_steps.sh b/ci/mac_ci_steps.sh index d080675125aa..c8e09228c1f3 100755 --- a/ci/mac_ci_steps.sh +++ b/ci/mac_ci_steps.sh @@ -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" diff --git a/ci/setup_gcs_cache.sh b/ci/setup_gcs_cache.sh new file mode 100755 index 000000000000..1c1c936f5f68 --- /dev/null +++ b/ci/setup_gcs_cache.sh @@ -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