From 88ed42ab38c92896a90ab06649b05a20c0a936f2 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Mon, 24 Jun 2019 13:14:41 -0700 Subject: [PATCH] build: create script for setting up RBE in local dev environment --- .bazelrc | 49 +++++++++++++++++++++++ .circleci/base-rbe-bazelrc | 30 -------------- .circleci/bazel.rc | 14 ------- .gitignore | 1 + scripts/local-dev/setup-rbe.sh | 71 ++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 44 deletions(-) delete mode 100644 .circleci/base-rbe-bazelrc create mode 100755 scripts/local-dev/setup-rbe.sh diff --git a/.bazelrc b/.bazelrc index f28f2e2937f0..205cc3aff80d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/.circleci/base-rbe-bazelrc b/.circleci/base-rbe-bazelrc deleted file mode 100644 index 3e48f629532f..000000000000 --- a/.circleci/base-rbe-bazelrc +++ /dev/null @@ -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 diff --git a/.circleci/bazel.rc b/.circleci/bazel.rc index e09d3ebaa7fa..5ecde131369c 100644 --- a/.circleci/bazel.rc +++ b/.circleci/bazel.rc @@ -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 diff --git a/.gitignore b/.gitignore index 240c7172cc56..8d91d3b418e5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ testem.log /.chrome /.git /.firebase +/.bazelrc.user diff --git a/scripts/local-dev/setup-rbe.sh b/scripts/local-dev/setup-rbe.sh new file mode 100755 index 000000000000..25ae18a43f9e --- /dev/null +++ b/scripts/local-dev/setup-rbe.sh @@ -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 + + \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; \ No newline at end of file