Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 0 additions & 30 deletions .circleci/base-rbe-bazelrc

This file was deleted.

14 changes: 0 additions & 14 deletions .circleci/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ testem.log
/.chrome
/.git
/.firebase
/.bazelrc.user
71 changes: 71 additions & 0 deletions scripts/local-dev/setup-rbe.sh
Original file line number Diff line number Diff line change
@@ -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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this script install gcloud?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't install gcloud because dependent on your platform we have to install it differently.

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;