Files
Alexei Fedotov b949c80383 darwin runner-init: re-provision on failure, region-pin S3 copy
Several fixes to the macOS runner provisioning in
`ci/praktika/infrastructure/runner/runner-init.py`:

- Rename `configure_macos` to `configure_darwin` for consistency with the
  rest of the codebase.
- Drop the provisioning marker `.clickhouse-ci-runner-init-version` when the
  runner loop raises on macOS, so the next boot re-runs `configure_darwin`
  (re-extracts `actions-runner`) instead of skipping it on the version gate
  and failing the same way again. Previously a missing `actions-runner`
  directory left the instance stuck rebooting with a `FileNotFoundError`
  from `os.chdir`. The marker path is centralized as
  `Runner.PROVISION_MARKER`.
- Substitute `config.runner_home` into the actions-runner install block via
  an `rf"""` string instead of recomputing `$HOME/actions-runner` in bash.
- Remove the temporary login-profile clearing block.
- Bump `version` to 71.

In `ci/infra/scripts/user_data_macos.txt`, pin the `aws s3 cp` of the
init script to `us-east-1` (where the `github-runners-data` bucket lives)
so it works from runners launched in any region.
2026-06-18 23:41:36 +02:00

51 lines
2.3 KiB
Plaintext

#!/usr/bin/env bash
# Bootstrap script for macOS GitHub Actions runners.
# Bootstraps Homebrew + Python, then hands off to the runner-init script
# fetched from S3 for the rest of provisioning (CloudWatch agent,
# actions-runner install, etc.). After changing this file, push it to the
# running fleet with `ci/infra/scripts/update_userdata.py`, which stops each
# instance, installs the new user_data, and starts it again.
set -xeuo pipefail
trap reboot EXIT
USER=ec2-user
# Pin HOME to the target user. In the EC2 user_data context this script runs as
# root, where HOME may be /var/root; the venv created below (and the runner-init
# handoff that runs `$HOME/venv/bin/python`) must resolve under /Users/$USER.
export HOME="/Users/$USER"
cd "$HOME"
# Install Homebrew if not already installed
if ! sudo -u "$USER" -i command -v brew &> /dev/null; then
echo "Installing Homebrew..."
sudo -u "$USER" -i bash -c 'NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
# Add Homebrew to PATH for Apple Silicon Macs
if [[ $(uname -m) == "arm64" ]]; then
sudo -u "$USER" -i bash -c "echo 'eval \"\$(/opt/homebrew/bin/brew shellenv)\"' >> ~/.zprofile"
fi
else
echo "Homebrew already installed"
sudo -u "$USER" -i brew update
fi
# Install Python, then upgrade it: `brew install` is a no-op on an already
# installed (even outdated) python@3, so a separate `brew upgrade` is needed for
# interpreter bumps to propagate on existing hosts. `brew upgrade` is a no-op
# when python@3 is already current (e.g. right after a fresh install).
echo "Installing python@3..."
sudo -u "$USER" -i brew install python@3
sudo -u "$USER" -i brew upgrade python@3
# Install / upgrade boto3 — the only third-party dependency of runner-init.py.
# `--upgrade` keeps it at the latest version on re-runs triggered by a
# user_data change.
echo "Installing Python packages into venv..."
sudo -u "$USER" -i bash -c '$(brew --prefix python@3)/bin/python3 -m venv --upgrade ~/venv && ~/venv/bin/pip install --upgrade boto3'
INIT_ENVIRONMENT=${INIT_ENVIRONMENT:-macos}
aws s3 cp --region us-east-1 "s3://github-runners-data/cloud-init/${INIT_ENVIRONMENT}.py" /tmp/runner-init.py
rm -rf "$HOME/actions-runner/_work"
sudo -u "$USER" -i bash -c "$HOME/venv/bin/python /tmp/runner-init.py --environment \"$INIT_ENVIRONMENT\""