Add remote caching to bazel builds (#10767)

* Add remote cache to linux builds

* Remove BES flags

* Remove BES flags from the right file

* Migrate all Bazel kokoro builds to use remote caching

* Remove BES logic

* Fix mac ruby tests

* Give mac/windows builds GCP access

* Adding quotes to prevent issues with common flags

* Adding command echoing in windows builds

* Try enabling command echoing again

* Adding invocation id for windows bazel build

* Third try

* Adding credentials to windows build
pull/10786/head
Mike Kruskal 2 years ago committed by GitHub
parent 7d1362c7ba
commit 79564c53af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      kokoro/common/bazel_flags.sh
  2. 71
      kokoro/common/bazel_wrapper.sh
  3. 3
      kokoro/linux/bazel.sh
  4. 2
      kokoro/macos/cpp/build.sh
  5. 22
      kokoro/macos/cpp/common.cfg
  6. 22
      kokoro/macos/objectivec_ios_debug/common.cfg
  7. 22
      kokoro/macos/objectivec_ios_release/common.cfg
  8. 22
      kokoro/macos/objectivec_osx/common.cfg
  9. 22
      kokoro/macos/php74/common.cfg
  10. 22
      kokoro/macos/php80/common.cfg
  11. 3
      kokoro/macos/python/build.sh
  12. 22
      kokoro/macos/python/common.cfg
  13. 3
      kokoro/macos/python_cpp/build.sh
  14. 22
      kokoro/macos/python_cpp/common.cfg
  15. 22
      kokoro/macos/ruby25/common.cfg
  16. 22
      kokoro/macos/ruby26/common.cfg
  17. 22
      kokoro/macos/ruby27/common.cfg
  18. 22
      kokoro/macos/ruby30/common.cfg
  19. 22
      kokoro/macos/ruby31/common.cfg
  20. 4
      kokoro/macos/test_php.sh
  21. 10
      kokoro/windows/bazel/build.bat
  22. 22
      kokoro/windows/bazel/common.cfg
  23. 3
      objectivec/DevTools/full_mac_build.sh
  24. 4
      ruby/travis-test.sh

@ -0,0 +1,46 @@
#!/bin/bash
# Helper for setting up common bazel flags in Kokoro.
#
# This script prints extra flags to a bazel invocation when it is run from
# Kokoro. When the special environment variables are not present (e.g., if you
# run Kokoro build scripts locally), this script only flips some debug settings.
#
# Example of running directly:
# bazel test $(path/to/bazel_flags.sh) //...
function bazel_flags::gen_invocation_id() {
# Create a new invocation ID and store in the artifacts dir.
local _invocation_id=$(uuidgen | tr A-Z a-z)
# Put the new invocation ID at the start of the output IDs file. Some
# Google-internal tools only look at the first entry, so this ensures the most
# recent entry is first.
local _ids_file=${KOKORO_ARTIFACTS_DIR}/bazel_invocation_ids
local _temp_ids=$(mktemp)
echo ${_invocation_id} > ${_temp_ids}
[[ -e ${_ids_file} ]] && cat ${_ids_file} >> ${_temp_ids}
mv -f ${_temp_ids} ${_ids_file}
echo -n ${_invocation_id}
}
# Prints flags to use on Kokoro.
function bazel_flags::kokoro_flags() {
[[ -n ${KOKORO_JOB_NAME:-} ]] || return
local -a _flags
_flags+=(
--invocation_id=$(bazel_flags::gen_invocation_id)
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/${KOKORO_JOB_NAME}
)
if [[ -n ${KOKORO_BAZEL_AUTH_CREDENTIAL:-} ]]; then
_flags+=( --google_credentials=${KOKORO_BAZEL_AUTH_CREDENTIAL} )
else
_flags+=( --google_default_credentials=true )
fi
echo "${_flags[@]}"
}
echo "$(bazel_flags::kokoro_flags) --keep_going --test_output=errors"

@ -1,71 +0,0 @@
#!/bin/bash
# Wrapper for invoking bazel on Kokoro.
#
# This script adds extra flags to a bazel invocation when it is run from Kokoro.
# When the special environment variables are not present (e.g., if you run
# Kokoro build scripts locally), this script is equivalent to the "bazel"
# command.
#
# Example of running directly:
# path/to/bazel_wrapper.sh build //...
#
# Example of `source`ing:
# source path/to/bazel_wrapper.sh
# bazel_wrapper build //...
function bazel_wrapper::gen_invocation_id() {
# Create a new invocation ID and store in the artifacts dir.
local _invocation_id=$(uuidgen | tr A-Z a-z)
# Put the new invocation ID at the start of the output IDs file. Some
# Google-internal tools only look at the first entry, so this ensures the most
# recent entry is first.
local _ids_file=${KOKORO_ARTIFACTS_DIR}/bazel_invocation_ids
local _temp_ids=$(mktemp)
echo ${_invocation_id} > ${_temp_ids}
[[ -e ${_ids_file} ]] && cat ${_ids_file} >> ${_temp_ids}
mv -f ${_temp_ids} ${_ids_file}
echo -n ${_invocation_id}
}
# Prints flags to use on Kokoro.
function bazel_wrapper::kokoro_flags() {
[[ -n ${KOKORO_BES_PROJECT_ID:-} ]] || return
local -a _flags
_flags+=(
--bes_backend=${KOKORO_BES_BACKEND_ADDRESS:-buildeventservice.googleapis.com}
--bes_results_url=https://source.cloud.google.com/results/invocations/
--invocation_id=$(bazel_wrapper::gen_invocation_id)
--project_id=${KOKORO_BES_PROJECT_ID} # --bes_instance_name in Bazel 5+
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache
)
if [[ -n ${KOKORO_BAZEL_AUTH_CREDENTIAL:-} ]]; then
_flags+=( --google_credentials=${KOKORO_BAZEL_AUTH_CREDENTIAL} )
else
_flags+=( --google_default_credentials=true )
fi
echo "${_flags[@]}"
}
# Runs bazel with Kokoro flags, if appropriate.
function bazel_wrapper() {
local -a _flags
# We might need to add flags. They need to come after any startup flags and
# the command, but before any terminating "--", so copy them into the _flags
# variable.
until (( ${#@} == 0 )) || [[ $1 == "--" ]]; do
_flags+=( "${1}" ); shift
done
# Set the `BAZEL` env variable to override the actual bazel binary to use:
${BAZEL:=bazel} "${_flags[@]}" $(bazel_wrapper::kokoro_flags) "${@}"
}
# If this script was called directly, run bazel. Otherwise (i.e., this script
# was `source`d), the sourcing script will call bazel_wrapper themselves.
(( ${#BASH_SOURCE[@]} == 1 )) && bazel_wrapper "${@}"

@ -39,8 +39,7 @@ function run {
-v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \
test \
--keep_going \
--test_output=streamed \
$(${GIT_REPO_ROOT}/kokoro/common/bazel_flags.sh) \
${ENVS[@]} \
$PLATFORM_CONFIG \
$BAZEL_CONFIG \

@ -14,4 +14,4 @@ source kokoro/macos/prepare_build_macos_rc
#
# Run build
#
bazel test //src/... -k --test_output=streamed
bazel test $(kokoro/common/bazel_flags.sh) //src/...

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/cpp/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/objectivec_ios_debug/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/objectivec_ios_release/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/objectivec_osx/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/php74/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/php80/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -9,4 +9,5 @@ cd $(dirname $0)/../../..
KOKORO_INSTALL_VENV=yes
source kokoro/macos/prepare_build_macos_rc
bazel test //python/... @upb//python/... -k --macos_minimum_os=10.9 --test_output=streamed
bazel test //python/... @upb//python/... $(kokoro/common/bazel_flags.sh) \
--macos_minimum_os=10.9

@ -9,3 +9,25 @@ action {
regex: "**/*"
}
}
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -9,4 +9,5 @@ cd $(dirname $0)/../../..
KOKORO_INSTALL_VENV=yes
source kokoro/macos/prepare_build_macos_rc
bazel test //python/... -k --macos_minimum_os=10.9 --test_output=streamed --define=use_fast_cpp_protos=true
bazel test //python/... $(kokoro/common/bazel_flags.sh) \
--macos_minimum_os=10.9 --define=use_fast_cpp_protos=true

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/python_cpp/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/ruby25/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/ruby26/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/ruby27/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/ruby30/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/macos/ruby31/build.sh"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -11,4 +11,6 @@ composer test_c
popd
git clean -fXd
bazel test //php:conformance_test_c --action_env=PATH --test_env=PATH --test_output=streamed
bazel test $(kokoro/common/bazel_flags.sh) \
--action_env=PATH --test_env=PATH \
//php:conformance_test_c

@ -13,9 +13,17 @@ bazel version
choco install bazel -y -i --version 5.1.0
bazel version
@rem Set invocation ID so that bazel run is known to kokoro
uuidgen > %KOKORO_ARTIFACTS_DIR%\bazel_invocation_ids
SET /p BAZEL_INTERNAL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%\bazel_invocation_ids
@rem Make paths as short as possible to avoid long path issues.
set BAZEL_STARTUP=--output_user_root=C:/tmp --windows_enable_symlinks
set BAZEL_FLAGS=--enable_runfiles --keep_going --test_output=streamed --verbose_failures
set BAZEL_FLAGS=--enable_runfiles --keep_going --test_output=errors ^
--verbose_failures ^
--invocation_id=%BAZEL_INTERNAL_INVOCATION_ID% ^
--google_credentials=%KOKORO_BAZEL_AUTH_CREDENTIAL% ^
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/%KOKORO_JOB_NAME%
@rem Build libraries first.
bazel %BAZEL_STARTUP% build //:protoc //:protobuf //:protobuf_lite %BAZEL_FLAGS% || goto :error

@ -3,3 +3,25 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/windows/bazel/build.bat"
timeout_mins: 1440
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}
}
bazel_setting {
project_id: "protobuf-build"
bes_backend_address: "buildeventservice.googleapis.com"
foundry_backend_address: "remotebuildexecution.googleapis.com"
upsalite_frontend_address: "https://source.cloud.google.com"
local_execution: true
# Need to be same as the fetch_keystore entry in the previous step.
auth_credential: {
keystore_config_id: 77103
keyname: "kokoro_gcp_service"
}
}

@ -8,7 +8,8 @@ set -eu
# Some base locations.
readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
readonly ProtoRootDir="${ScriptDir}/../.."
readonly BazelFlags="-k --announce_rc --test_output=errors --macos_minimum_os=10.9"
readonly BazelFlags="--announce_rc --macos_minimum_os=10.9 \
$(${ScriptDir}/../../kokoro/common/bazel_flags.sh)"
# Invoke with BAZEL=bazelisk to use that instead.
readonly BazelBin="${BAZEL:=bazel}"

@ -5,8 +5,8 @@ set -ex
test_version() {
version=$1
bazel_args=" \
-k --test_output=streamed \
bazel_args="\
$(../kokoro/common/bazel_flags.sh) \
--action_env=PATH \
--action_env=GEM_PATH \
--action_env=GEM_HOME \

Loading…
Cancel
Save