Last active
August 31, 2020 07:16
-
-
Save brymck/cffde1068dc9c6c7e9948e44bad81388 to your computer and use it in GitHub Desktop.
Install Buildkite with Bazel on GCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I'm using a Debian 9 image on an n1-standard-1 machine type | |
#----------------------------------------------------------------------------------------------------------------------- | |
# Configuration | |
#----------------------------------------------------------------------------------------------------------------------- | |
# This is the token you get from going to | |
# https://buildkite.com/organizations/your-organization/agents | |
# and clicking Reveal Agent Token | |
BUILDKITE_AGENT_TOKEN=foo | |
# Optional URI for a key in Google Cloud Storage if you want to bring your own | |
PRIVATE_KEY_URI=gs://bucket-name/object-name | |
#----------------------------------------------------------------------------------------------------------------------- | |
# Install Bazel | |
#----------------------------------------------------------------------------------------------------------------------- | |
# This follows the instructions on | |
# https://docs.bazel.build/versions/master/install-ubuntu.html | |
# Add apt repository for Bazel | |
sudo apt-get install -y curl gnupg | |
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg | |
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/ | |
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list | |
# Install Bazel, OpenJDK and Python | |
sudo apt-get update && sudo apt-get install -y bazel openjdk-11-jdk python | |
#----------------------------------------------------------------------------------------------------------------------- | |
# Install Buildkite | |
#----------------------------------------------------------------------------------------------------------------------- | |
# This follows the instructions on | |
# https://buildkite.com/docs/agent/v3/debian | |
# Add apt repository for Buildkite | |
sudo apt-get install -y apt-transport-https dirmngr | |
sudo apt-key adv --keyserver ipv4.pool.sks-keyservers.net --recv-keys 32A37959C2FA5C3C99EFBC32A79206696452D198 | |
echo "deb https://apt.buildkite.com/buildkite-agent stable main" | sudo tee /etc/apt/sources.list.d/buildkite-agent.list | |
# Install the Buildkite agent | |
sudo apt-get update && sudo apt-get install -y buildkite-agent | |
# Configure the agent token | |
sudo sed -i "s/xxx/$BUILDKITE_AGENT_TOKEN/g" /etc/buildkite-agent/buildkite-agent.cfg | |
# Uncomment lines for getting tags from GCP | |
sudo sed -i 's/^# tags-from-gcp/tags-from-gcp/g' /etc/buildkite-agent/buildkite-agent.cfg | |
# Start the agent | |
sudo systemctl enable buildkite-agent && sudo systemctl start buildkite-agent | |
# Create SSH directories for the buildkite-agent user and ensure they have the right permissions | |
sudo mkdir -p /var/lib/buildkite-agent/.ssh/ | |
sudo chmod 700 /var/lib/buildkite-agent/.ssh/ | |
sudo chown -R buildkite-agent:buildkite-agent /var/lib/buildkite-agent/.ssh/ | |
# Use a preexisting private key if its URI is provided, otherwise create a new SSH key | |
if [ -n $PRIVATE_KEY_URI ]; then | |
# Copy the private key to Buildkite's SSH directories | |
gsutil $PRIVATE_KEY_URI /var/lib/buildkite-agent/.ssh/id_rsa | |
sudo chmod 600 /var/lib/buildkite-agent/.ssh/id_rsa | |
else | |
# Create an SSH key with no passphrase in the Buildkite agent SSH directory and assign it the agent's user and group | |
sudo ssh-keygen -t rsa -b 4096 -C buildkite -N '' -f /var/lib/buildkite-agent/.ssh/id_rsa | |
fi | |
# Ensure buildkite-agent owns its SSH directories | |
sudo chown -R buildkite-agent:buildkite-agent /var/lib/buildkite-agent/.ssh/ | |
# Add the contents of /var/lib/buildkite-agent/.ssh/id_rsa.pub to your GitHub keys via | |
# https://github.com/settings/ssh/new | |
sudo cat /var/lib/buildkite-agent/.ssh/id_rsa.pub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment