You’ve got a newly installed macos Monterey machine you want to use as a gitlab-runner host to test and build your ios and macos projects on. What do you need?

macos command line tools

Get the macos Command Line Tools. In a terminal, run:

xcode-select --install
softwareupdate -l

# Then pick the most recent version of Command Line tools, e.g.
softwareupdate --install "Command Line Tools for Xcode-13.3"
sudo xcodebuild -license accept

homebrew

Then install homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

and this Brewfile (save it to ~/Brewfile)

brew "asdf"
brew "bash"
brew "bash-completion"
brew "ack"
brew "autoconf"
brew "automake"
brew "coreutils"
brew "curl"
brew "gettext"
brew "git"
brew "gnu-sed"
brew "gnu-tar"
brew "gnu-indent"
brew "gnu-which"
brew "pkg-config"
brew "robotsandpencils/made/xcodes"

Then run:

brew bundle

in the same folder as the Brewfile (e.g. cd ~ && brew bundle).

Xcode

And get and install the latest Xcode so you have the ios simulator, etc:

XCODES_USERNAME="your_apple_id" XCODES_PASSWORD="your_apple_id_password" xcodes install --latest

gitlab-runner

Now install and configure the gitlab-runner:

# Install gitlab-runner
# uses `arch` to fetch the correct version
[ "$(arch)" = "i386" ] && sudo curl --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64" || sudo curl --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"

sudo chmod +x /usr/local/bin/gitlab-runner

# Register the runner
gitlab-runner register

# Install gitlab-runner as a user service.
# PLEASE NOTE you must enable autologin to this user
# on the macos machine or your runner will be showing
# as `stuck` the next time your macos machine reboots
# and you don't login.
su - $(whoami)
cd ~
gitlab-runner install
gitlab-runner start

Disable macos sleep for the logged in user

Ensure the mac doesn’t sleep, if you don’t set your mac not to sleep, it will, and then your runner won’t be able to pick up jobs, and will be showing as stuck:

sudo pmset -a sleep 0; sudo pmset -a hibernatemode 0; sudo pmset -a disablesleep 1

Optional ruby install with asdf when using Fastlane

I also need ruby, because I’m using Fastlane to manage the ios and macos builds, and I’m using asdf to manage ruby versions:

echo "ruby 2.7.6" > ~/.tool-versions
asdf plugin-add ruby
asdf install ruby 2.7.6
gem install fastlane