1#!/bin/bash 2# Copyright 2021 The gRPC Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# This wrapper allows running concurrent instances of bazel build/test by running 17# bazel under a docker container. 18# This is especially useful for running bazel RBE builds, since inside 19# the container, bazel won't have access to local build cache. 20# Access to the local workspace is provided by mounting the workspace 21# as a volume to the docker container. That also means that any changes 22# in the workspace will be visible to the bazel instance running inside 23# the container (but also this is a similar scenario to making changes 24# to local files when bazel is running normally). 25 26# Usage: 27# tools/docker_runners/examples/concurrent_bazel.sh ANY_NORMAL_BAZEL_FLAGS_HERE 28 29set -ex 30 31# change to grpc repo root 32cd "$(dirname "$0")/../../.." 33 34# use the default docker image used for bazel builds 35export DOCKERFILE_DIR=tools/dockerfile/test/bazel 36 37# Bazel RBE uses application default credentials from localhost to authenticate with RBE servers. Use a trick to make the credentails accessible from inside the docker container." 38APPLICATION_DEFAULT_CREDENTIALS_DIR="$HOME/.config/gcloud" 39export DOCKER_EXTRA_ARGS="-v=${APPLICATION_DEFAULT_CREDENTIALS_DIR}:/application_default_credentials:ro -e=GOOGLE_APPLICATION_CREDENTIALS=/application_default_credentials/application_default_credentials.json" 40 41# Run bazel inside a docker container (local git workspace will be mounted to the container) 42tools/docker_runners/run_in_docker.sh bazel "$@" 43