build: create script for setting up RBE in local dev environment (#16375)

This commit is contained in:
Joey Perrott
2019-06-26 08:53:46 -07:00
committed by Andrew Seguin
parent a5f8ee9b09
commit 93f4b584ac
5 changed files with 121 additions and 44 deletions
+49
View File
@@ -58,3 +58,52 @@ build --strategy=AngularTemplateCompile=worker
# Use the legacy AOT compiler strategy. We don't want to compile with Ivy nor with "ngtsc" which
# does not generate factory files which are needed for AOT.
build --define=compile=legacy
################################
# Remote Execution Setup #
################################
# Use the Angular team internal GCP instance for remote execution.
build:remote --remote_instance_name=projects/internal-200822/instances/default_instance
build:remote --project_id=internal-200822
# Setup the build strategy for various types of actions. Mixing "local" and "remote"
# can cause unexpected results and we want to run everything remotely if possible.
build:remote --spawn_strategy=remote
build:remote --strategy=Javac=remote
build:remote --strategy=Closure=remote
build:remote --strategy=Genrule=remote
build:remote --define=EXECUTOR=remote
# Setup the remote build execution servers.
build:remote --remote_cache=remotebuildexecution.googleapis.com
build:remote --remote_executor=remotebuildexecution.googleapis.com
build:remote --tls_enabled=true
build:remote --auth_enabled=true
# Setup the toolchain and platform for the remote build execution. The platform
# is automatically configured by the "rbe_autoconfig" rule in the project workpsace.
build:remote --crosstool_top=@rbe_default//cc:toolchain
build:remote --host_javabase=@rbe_default//java:jdk
build:remote --javabase=@rbe_default//java:jdk
build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:remote --extra_execution_platforms=//tools:rbe_platform
build:remote --host_platform=//tools:rbe_platform
build:remote --platforms=//tools:rbe_platform
build:remote --extra_toolchains=@rbe_default//config:cc-toolchain
# Setup Build Event Service
build:remote --bes_backend=buildeventservice.googleapis.com
build:remote --bes_timeout=30s
build:remote --bes_results_url="https://source.cloud.google.com/results/invocations/"
# Set remote caching settings
build:remote --remote_accept_cached=true
################################
# Local Environment Setup #
################################
# Load any settings which are specific to the current user. Needs to be *last* statement
# in this config, as the user configuration should be able to overwrite flags from this file.
try-import .bazelrc.user
-30
View File
@@ -1,30 +0,0 @@
# Setup the build strategy for various types of actions. Mixing "local" and "remote"
# can cause unexpected results and we want to run everything remotely if possible.
build:remote --spawn_strategy=remote
build:remote --strategy=Javac=remote
build:remote --strategy=Closure=remote
build:remote --strategy=Genrule=remote
build:remote --define=EXECUTOR=remote
# Setup the remote build execution servers.
build:remote --remote_cache=remotebuildexecution.googleapis.com
build:remote --remote_executor=remotebuildexecution.googleapis.com
build:remote --tls_enabled=true
build:remote --auth_enabled=true
# Setup Build Event Service
build:remote --bes_backend=buildeventservice.googleapis.com
build:remote --bes_timeout=30s
build:remote --bes_results_url="https://source.cloud.google.com/results/invocations/"
# Setup the toolchain and platform for the remote build execution. The platform
# is automatically configured by the "rbe_autoconfig" rule in the project workpsace.
build:remote --crosstool_top=@rbe_default//cc:toolchain
build:remote --host_javabase=@rbe_default//java:jdk
build:remote --javabase=@rbe_default//java:jdk
build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
build:remote --extra_execution_platforms=//tools:rbe_platform
build:remote --host_platform=//tools:rbe_platform
build:remote --platforms=//tools:rbe_platform
build:remote --extra_toolchains=@rbe_default//config:cc-toolchain
-14
View File
@@ -5,17 +5,3 @@
# Save downloaded repositories in a location that can be cached by CircleCI. This helps us
# speeding up the analysis time significantly with Bazel managed node dependencies on the CI.
build --repository_cache=/home/circleci/bazel_repository_cache
########################################
# Remote Build Execution support on CI #
########################################
# Load base settings for remote build execution.
import %workspace%/.circleci/base-rbe-bazelrc
# Use the Angular team internal GCP instance for remote execution.
build:remote --remote_instance_name=projects/internal-200822/instances/default_instance
build:remote --project_id=internal-200822
# Always read from remote cache on CI.
build:remote --remote_accept_cached=true
+1
View File
@@ -42,3 +42,4 @@ testem.log
/.chrome
/.git
/.firebase
/.bazelrc.user
+71
View File
@@ -0,0 +1,71 @@
#!/bin/bash
# A script for automatically configuring a user's local dev
# environment to use Remote Build Execution.
# Determine the root directory of the Angular github repo.
github_directory_root=$(git rev-parse --show-toplevel 2> /dev/null);
if [[ $? -ne 0 ]]; then
echo "This command must be run from within the cloned \"angular/components\" repository."
exit 1;
fi
# Confirm gcloud installed and available as a command.
if [ ! -x "$(command -v gcloud)" ]; then
echo "gcloud command is not available. Please install gcloud before continuing."
exit 1;
fi
# Confirm the parameter provided to the script is a directory
if [[ ! -d $1 ]]; then
echo -e "Invalid command syntax.
\e[1mUsage:\e[0m $0 <ServiceAccountKeyLocation>
\e[1mExample:\e[0m ./setup-rbe ~/my_key_storage_directory/
The directory provided will be used to store the GCP service account key
for the angular-local-dev service account. This key will then be used to
authenticate for usage of the Remote Build Execution system and Remote Caching.
";
exit 1;
fi
credentials_directory=$(readlink -f $1)
if [[ ! -d $credentials_directory ]]; then
echo "Can't find the absolute directory path"
exit 1;
fi
# Create the service account key in the provided directory.
echo "Checking provided directory for a service account key."
json_key_filepath="$credentials_directory/angular-local-dev-key.json";
if [[ -f $json_key_filepath ]]; then
echo "Angular Local Dev key already exists, reusing this key."
else
# Confirm the user is already logged into gcloud, if they aren't
# attempt to login
echo "Checking gcloud login state."
gcloud auth print-identity-token &> /dev/null;
if [[ $? -ne 0 ]]; then
echo "Not currently logged into gcloud. Starting gcloud login now."
gcloud auth login;
if [[ $? -ne 0 ]]; then
echo "gcloud login failed. Aborting.";
exit 2
fi
fi
gcloud iam service-accounts keys create $json_key_filepath \
--iam-account angular-local-dev@internal-200822.iam.gserviceaccount.com \
--quiet --verbosity none --project internal-200822;
echo $?;
if [[ $? -ne 0 ]]; then
echo "Downloading service account key failed. Aborting."
exit 2;
fi
fi
# The full path to the .bazelrc.user file
bazelrc_user_filepath="$github_directory_root/.bazelrc.user";
# Create the bazelrc.user file, echo the config flags into the file.
touch $bazelrc_user_filepath;
echo "build --config=remote" >> $bazelrc_user_filepath;
echo "build --google_credentials=$json_key_filepath" >> $bazelrc_user_filepath;