[libcxx-commits] [libcxx] 18e21e6 - [libc++] CI: Setup BuildKite agents through launchd

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 16 08:40:17 PDT 2021


Author: Louis Dionne
Date: 2021-07-16T11:40:08-04:00
New Revision: 18e21e6832007384dec8163baa7e1bb69f458b29

URL: https://github.com/llvm/llvm-project/commit/18e21e6832007384dec8163baa7e1bb69f458b29
DIFF: https://github.com/llvm/llvm-project/commit/18e21e6832007384dec8163baa7e1bb69f458b29.diff

LOG: [libc++] CI: Setup BuildKite agents through launchd

This makes sure that even if a node goes down, the BuildKite agent will
be started again when it goes back up.

Added: 
    

Modified: 
    libcxx/utils/ci/macos-ci-setup

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/ci/macos-ci-setup b/libcxx/utils/ci/macos-ci-setup
index 3b2f42a8e79e..058d4f5441a7 100755
--- a/libcxx/utils/ci/macos-ci-setup
+++ b/libcxx/utils/ci/macos-ci-setup
@@ -4,36 +4,96 @@
 # An additional requirement that is *not* handled by this script is the
 # installation of Xcode, which requires manual intervention.
 #
-# This script should be run from an administrator account. It can be run
-# without having to clone the LLVM repository with:
+# This script should first be run from an administrator account to install
+# the dependencies necessary for running CI. It can be run without having
+# to clone the LLVM repository with:
 #
 #   $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)"
 #
 # Once the necessary dependencies have been installed, you can switch
-# to a non-administrator account and run:
+# to a non-administrator account and run the script again, passing the
+# --setup-launchd argument. That will install a Launchd agent to run the
+# BuildKite agent whenever the current user is logged in. You should enable
+# automatic login for that user, so that if the CI node goes down, the user
+# is logged back in automatically when the node goes up again, and the
+# BuildKite agent starts automatically.
+#
+# Alternatively, you can simply run the BuildKite agent by hand using:
 #
 #   $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds
 
 set -e
 
-if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then
-  echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script."
-  exit 1
-fi
+# Install a Launchd agent that will automatically start the BuildKite agent at login
+if [[ ${1} == "--setup-launchd" ]]; then
+  HOMEBREW_PREFIX="$(brew --prefix)"
+  cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+  <key>Label</key>
+  <string>libcxx.buildkite-agent</string>
+
+  <key>ProgramArguments</key>
+  <array>
+    <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string>
+    <string>start</string>
+    <string>--build-path</string>
+    <string>${HOME}/libcxx.buildkite-agent/builds</string>
+  </array>
+
+  <key>EnvironmentVariables</key>
+  <dict>
+    <key>PATH</key>
+    <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
+  </dict>
+
+  <key>RunAtLoad</key>
+  <true/>
+
+  <key>KeepAlive</key>
+  <dict>
+    <key>SuccessfulExit</key>
+    <false/>
+  </dict>
 
-# Install Homebrew
-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
+  <key>ProcessType</key>
+  <string>Interactive</string>
 
-# Install the required tools to run CI
-brew install sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent
+  <key>ThrottleInterval</key>
+  <integer>30</integer>
 
-CFG_DIR="$(brew --prefix)/etc/buildkite-agent"
+  <key>StandardOutPath</key>
+  <string>${HOME}/libcxx.buildkite-agent/stdout.log</string>
 
-version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')"
-arch="$(uname -m)"
+  <key>StandardErrorPath</key>
+  <string>${HOME}/libcxx.buildkite-agent/stderr.log</string>
+</dict>
+</plist>
+EOF
 
-# Setup the tags of the agent
-echo "tags=\"queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}\"" >> "${CFG_DIR}/buildkite-agent.cfg"
+  echo "Starting BuildKite agent"
+  launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
 
-# Setup the BuildKite Agent token
-sed -i '' "s/xxx/${BUILDKITE_AGENT_TOKEN}/g" "${CFG_DIR}/buildkite-agent.cfg"
+else
+  echo "Installing CI dependencies for macOS"
+
+  if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then
+    echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script."
+    exit 1
+  fi
+
+  # Install Homebrew
+  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
+  HOMEBREW_PREFIX="$(brew --prefix)"
+
+  # Install the required tools to run CI
+  brew install sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent
+
+  # Setup BuildKite Agent config
+  version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')"
+  arch="$(uname -m)"
+  sed -i '' "s/token=xxx/token=${BUILDKITE_AGENT_TOKEN}/g" "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg"
+  echo "tags=\"queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}\"" >> "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg"
+fi


        


More information about the libcxx-commits mailing list