# Runner image recipes

Example runner images you can copy: a macOS image that boots iOS simulators and an Android emulator on demand, plus
browser, mobile-release and Linux Android images.

[← Back to README](https://kinhin.dev/index.md)

An image is baked once by `kinhin image prepare` and cloned per job, so anything a recipe installs is on every runner
from the first second of the job and costs nothing per run. The examples below are recipes, not defaults: change the
versions, labels and names to yours.

## What a recipe is

Every recipe has three parts:

| Part | Where | What it does |
| --- | --- | --- |
| Base image | `image:` / `base_image:` | The OS and what ships with it. A published Tart image, a local Tart VM, or a Debian/Ubuntu OCI image for the Linux runtimes. |
| Provision script | `provision_script`, or a pool's | Runs once inside the image after the runner agents install. Homebrew and mise are in the Tart base; `apt-get` in the Linux ones. |
| Labels | `labels:` on an `images:` entry, or a pool's | What `runs-on:` asks for. See [Choosing the image per job](https://kinhin.dev/guide/runtimes.md#choosing-the-image-per-job). |

Which key applies where:

| Runtime | Script key | Runs as | Budget |
| --- | --- | --- | --- |
| Tart (macOS **and** Linux VMs) | top-level `provision_script` | `admin` | 30 minutes |
| apple/container | `container.provision_script`, or a pool's | `root` | 30 minutes, shared with the rest of the build |
| Docker | `docker.provision_script` | `root` | 30 minutes |

- **The top-level script is shared by every Tart bake.** One `provision_script` bakes into `image:`, every `images:`
  entry and every Linux Tart VM, so branch on the guest OS (`uname -s`) instead of keeping one script per image. The
  container and Docker keys are separate on purpose, so a macOS script cannot break a Linux bake.
- **…and on the image's role, not only its OS.** There is one script per Mac, not one per Tart image, so a shared
  script has to decide each role's work from what its base carries: the mobile branch below runs only when
  `xcodebuild -version` answers, so the plain `image:` and the `macos` and `web` entries (no full Xcode) skip it
  instead of downloading a simulator runtime and an Android SDK. A base of your own that does have Xcode but must not
  get a toolchain cannot be told apart from inside the guest: give it a marker file in the base
  (`/etc/kinhin-role`, then test for it) or keep it in a second `config.yaml` on another Mac.
- **The script is your version pin.** A Tart bake starts from the pristine base and replaces the image only when
  everything succeeded, so edit the script and re-prepare to change versions. Log the versions at the end
  (`java -version`, `xcodebuild -version`): the output is the audit trail in `kinhin logs`.
- **The script has a 30-minute budget.** An iOS platform download is several gigabytes, and an Android system image
  one more, so keep each script to what its image needs. If it overruns, start from a base that already carries the
  toolchain instead of installing it.

## macOS with iOS simulators and an Android emulator

A named `xcode` image on a local Tart VM, plus the macOS branch of a shared provision script. The image itself stays
warm; the simulator and the emulator boot per job, so nothing idles in a booted simulator.

```yaml
# config.yaml
image: "ghcr.io/cirruslabs/macos-golden-gate-base:latest"   # the plain fleet image
provision_script: "~/kinhin/provision-mobile.sh"             # baked into every Tart image
images:
  - name: xcode
    base_image: "xcode-base"      # the local Tart VM you prepared
    labels: ["xcode"]             # runs-on: [self-hosted, macos, arm64, xcode]
    warm_pool: 1                  # keep one VM of this image booted for the next job
```

`xcode-base` is a VM you created and booted once yourself (Tart's documentation covers building one); kinhin only bakes
its runner agents and your script into it. `kinhin doctor` flags a `base_image` that is neither a published image, a
digest pin of one, nor a local VM, so a typo does not surface as a failed clone.

The script (one file, so it exits early on a Linux guest):

```bash
#!/bin/bash
# ~/kinhin/provision-mobile.sh — baked into every Tart image, so it branches on the guest
set -euo pipefail

if [[ "$(uname -s)" != "Darwin" ]]; then
  echo "not a macOS guest; nothing to install for the mobile image"
  exit 0
fi

# One script bakes into every Tart image, so the mobile role is selected by what the base carries: only an image with
# full Xcode (`xcode-base`, `macos-golden-gate-xcode`) gets the simulator runtime and the Android SDK. The plain
# `image:` and the `macos` and `web` entries skip this whole branch.
if ! xcodebuild -version >/dev/null 2>&1; then
  echo "no full Xcode in this base; the mobile toolchain belongs to the xcode/mobile images"
  exit 0
fi

# Full Xcode is in the base image; add the iOS platform and its simulator runtime.
xcodebuild -downloadPlatform iOS
runtime=$(xcrun simctl list runtimes | grep -o 'com\.apple\.CoreSimulator\.SimRuntime\.iOS-[0-9-]*' | tail -1)
for device in "iPhone 15" "iPhone 16"; do
  xcrun simctl list devices | grep -qF "${device} (" ||
    xcrun simctl create "$device" "com.apple.CoreSimulator.SimDeviceType.${device// /-}" "$runtime"
done

# Android: a JDK (sdkmanager is a Java program), then the command-line tools from
# Google, one platform, one arm64 system image and an AVD.
brew install openjdk@17
export JAVA_HOME="$(brew --prefix openjdk@17)/libexec/openjdk.jdk/Contents/Home"
export PATH="$JAVA_HOME/bin:$PATH"
export ANDROID_HOME="$HOME/android-sdk"
if [ ! -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
  tmp=$(mktemp -d)
  curl -fsSL "https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip" -o "$tmp/tools.zip"
  unzip -q "$tmp/tools.zip" -d "$tmp"
  mkdir -p "$ANDROID_HOME/cmdline-tools"
  mv "$tmp/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
  rm -rf "$tmp"
fi
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
yes | "$SDKMANAGER" --sdk_root="$ANDROID_HOME" --licenses >/dev/null || true
"$SDKMANAGER" --sdk_root="$ANDROID_HOME" \
  "emulator" "platform-tools" "platforms;android-34" \
  "system-images;android-34;google_apis;arm64-v8a"
echo no | "$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" create avd -n kinhin-android \
  -k "system-images;android-34;google_apis;arm64-v8a" -g google --force

# The audit trail in `kinhin logs`: a missing piece fails the bake, not the first job.
java -version
"$SDKMANAGER" --sdk_root="$ANDROID_HOME" --list_installed
xcrun simctl list runtimes
```

Bake it, then watch a job use it:

```bash
kinhin image prepare --image xcode     # or --all, for image: and every images: entry
kinhin image list                      # the image, its size and whether a runner is using it
```

```yaml
# .github/workflows/mobile.yml
on: workflow_dispatch

jobs:
  ios:
    runs-on: [self-hosted, macos, arm64, xcode]
    steps:
      - uses: actions/checkout@v4
      - run: xcodebuild -version && xcrun simctl list devices available

  android:
    runs-on: [self-hosted, macos, arm64, xcode]
    env:
      ANDROID_HOME: /Users/admin/android-sdk
      ANDROID_SDK_ROOT: /Users/admin/android-sdk
      JAVA_HOME: /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home
    steps:
      - uses: actions/checkout@v4
      - name: Boot the emulator
        run: |
          "$ANDROID_HOME/emulator/emulator" -avd kinhin-android \
            -no-window -no-audio -no-snapshot-save &
          "$ANDROID_HOME/platform-tools/adb" wait-for-device
          until [ "$("$ANDROID_HOME/platform-tools/adb" shell getprop sys.boot_completed | tr -d '\r')" = 1 ]; do
            sleep 5
          done
      - run: ./gradlew connectedCheck
```

The variables go in the job's `env:` (as above) rather than in the image: macOS does not read `/etc/profile.d`, and a
workflow step is not a login shell in any case. `JAVA_HOME` is the `openjdk@17` the script installed, which Gradle
needs. This repository's own `mobile-capture` job boots its emulator the same way (`.github/workflows/video.yml`),
with `Pixel_9` as the AVD name.

### Caveats worth knowing before you copy it

- **The emulator is software-rendered.** Apple's Virtualization framework gives nested virtualization to Linux guests
  only, so a macOS guest has no Hypervisor.framework (`sysctl -n kern.hv_support` prints `0` inside the VM) and the
  emulator cannot use hardware acceleration. It still boots and runs a headless instrumented test, but in minutes, not
  seconds, and the VM wants its RAM ([Hardware & sizing](https://kinhin.dev/guide/hardware.md)). Prefer a long job timeout and
  `-no-window -no-audio`. See [Tart's FAQ](https://tart.run/faq) for the framework limit.
- **A local VM base is never followed by `image_updates`.** `xcode-base` has no registry, so `image update` never
  checks it: rebuild the local VM, then `kinhin image prepare --image xcode`. A **registry** base is different: pin it
  with `kinhin image digest` and let `update: auto` rebuild it (see
  [Upgrading Xcode or macOS images](https://kinhin.dev/guide/upgrading-xcode-macos-images.md#let-kinhin-follow-the-registry)).
- **One image is 40–60 GB, more with Xcode and an SDK.** Decide that before you add a second one; `kinhin image prune`
  (or `kinhin image delete NAME --yes`) reclaims what nothing uses.
- **Label selection is GitHub-only.** Other forges register runners with the fleet labels, so their jobs always run on
  `image:` ([Runtimes](https://kinhin.dev/guide/runtimes.md#choosing-the-image-per-job)).

## More macOS images

Each row is a separate `images:` entry with its own `labels:`, baked from the same shared `provision_script` — that is
where its extra tools go, as further branches of it. Because one script serves every Tart image, each branch selects
itself from what the base carries (the `xcodebuild` guard above is what keeps the mobile branch off the plain base);
the rows that share a base and need different extras are the ones to split with a marker file, as described above.

| Entry | `base_image` | What it adds | Typical `runs-on:` |
| --- | --- | --- | --- |
| `macos` | `ghcr.io/cirruslabs/macos-golden-gate-base:latest` | Nothing but the runner agents and mise: Swift packages, `swift build`, native macOS apps | `[self-hosted, macos, arm64]` |
| `xcode` | `xcode-base` or `ghcr.io/cirruslabs/macos-golden-gate-xcode:latest` | Full Xcode, iOS platform, simulators, Android SDK + AVD | `[self-hosted, macos, arm64, xcode]` |
| `apple` | `ghcr.io/cirruslabs/macos-golden-gate-xcode:latest` | Every Apple platform runtime, for watchOS/tvOS/visionOS jobs | `[self-hosted, macos, arm64, apple]` |
| `web` | `ghcr.io/cirruslabs/macos-golden-gate-base:latest` | Node via mise, Playwright and Cypress browsers | `[self-hosted, macos, arm64, web]` |
| `mobile` | `xcode-base` | Xcode, JDK, Android SDK, Ruby 3.2+ and fastlane for `kinhin mobile init` workflows | `[self-hosted, macos, arm64, mobile]` |

All-platforms runtimes, in the macOS branch of the script:

```bash
for platform in watchOS tvOS visionOS; do xcodebuild -downloadPlatform "$platform"; done
```

A web image, where the browsers are baked instead of downloaded per job:

```bash
# macOS branch
mise use --global node@22
corepack enable
npx --yes playwright@1.65.2 install chromium firefox webkit
npx --yes cypress install
```

**Browsers belong to a Playwright version.** Both browser recipes bake `playwright@1.65.2`, so the installed browser
builds match that release. A job whose project pins another Playwright version does not find its browsers in the image
and downloads them itself (or fails, if the download is blocked), so keep the image's pin in step with your projects —
re-bake after a Playwright upgrade — or leave the browsers to the job.

A mobile-release image, matching what [Mobile releases with fastlane](https://kinhin.dev/guide/mobile-fastlane.md) needs on the runner:

```bash
# macOS branch
mise use --global ruby@3.3 fastlane@latest
gem install bundler
java -version && bundle --version && fastlane --version
```

## Linux images

Linux jobs run on apple/container or Docker, and those images install toolchains with `kinhin-toolchain install` per
job unless a pool bakes them ([Per-job toolchains](https://kinhin.dev/guide/toolchains.md#per-job-toolchains)). Bake when every job on the pool
wants the same thing and the download is big. A base pinned with `@sha256:` never moves on its own, and a plain
rebuild of a Linux image starts from the previous bake, so pin the base or use `kinhin image update --apply` when you
want a newer one ([Linux images](https://kinhin.dev/guide/upgrading-xcode-macos-images.md#linux-images)).

| Image | Base | Bakes | Use it for |
| --- | --- | --- | --- |
| `kinhin-ci-linux` | `ubuntu:24.04` | Nothing (the default) | Most jobs; install toolchains per job |
| `kinhin-ci-linux-android` | `ubuntu:24.04` | JDK 17, Android SDK, NDK r26 | `./gradlew assembleDebug`, lint, unit tests |
| `kinhin-ci-linux-browser` | `ubuntu:24.04` | Playwright's system dependencies and browsers (pinned `playwright@1.65.2`) | Browser E2E without a per-job download, when the project uses that Playwright version |
| `kinhin-ci-linux-docker` | `ubuntu:24.04` | Agents plus `docker: true` | `docker build`, `docker compose`, testcontainers |
| `kinhin-ci-linux-x64` | `ubuntu:24.04`, `platform: linux/amd64` | Agents as x64 | x86_64-only toolchains, under Rosetta |

The Android pool is the worked example: the script is
[`examples/linux-android/provision-android.sh`](https://github.com/RabinApps/kinhin/blob/main/examples/linux-android/provision-android.sh), and the pool needs an
image of its own so its SDK bakes nowhere else:

```yaml
container:
  pools:
    linux-large-android: # runs-on: [self-hosted, arm64, linux, kinhin-container-linux-large-android]
      platform: linux/amd64 # the NDK has no Linux arm64 host tools before r31
      cpus: 4
      memory_gb: 12
      image: kinhin-ci-linux-android
      provision_script: "~/kinhin/provision-android.sh"
```

```bash
kinhin image prepare --container --pool linux-large-android
```

A browser pool, baked once so no job downloads Chromium:

```bash
#!/bin/bash
# container.provision_script — runs as root in a Debian/Ubuntu image
apt-get update -qq
apt-get install -y -qq --no-install-recommends ca-certificates curl nodejs npm
npx --yes playwright@1.65.2 install --with-deps chromium firefox webkit
```

A Docker-in-Docker pool (testcontainers, `docker compose up`), which needs no script at all:

```yaml
container:
  docker: true
  pools:
    linux-docker:
      image: kinhin-ci-linux-docker
      labels: [linux, docker]
      cpus: 4
      memory_gb: 12
```

An x64 pool: a separate image, because the platform is baked in.

```yaml
container:
  pools:
    linux-x64:
      image: kinhin-ci-linux-x64
      labels: [linux]
      platform: linux/amd64
```

```bash
kinhin image prepare --container --pool linux-x64
```

An Android emulator is not a Linux image recipe. Neither runtime gives nested virtualization, so the emulator runs in
software wherever it runs; this repository's own Android screenshot job runs it on the macOS image for that reason
([Android SDK on Linux](https://kinhin.dev/guide/toolchains.md#android-sdk-on-linux) covers builds, not emulators).

## Prepare, update and clean up

```bash
kinhin image prepare                      # image: only
kinhin image prepare --image xcode        # one named images: entry
kinhin image prepare --all                # image: and every images: entry, one after another
kinhin image prepare --container --pool linux-large-android
kinhin image prepare --docker
kinhin image prepare --project owner/name # that repo's derived toolchain image, ahead of its first job
kinhin image digest ghcr.io/cirruslabs/macos-golden-gate-xcode:latest  # the @sha256: to pin
kinhin image update [--apply] [--image xcode]   # follow the registry
kinhin image rollback --image xcode             # rebuild from the digest it was baked from
kinhin image list                          # every image, its size, who is using it
kinhin image delete xcode                  # report only; add --yes to delete
kinhin image prune                         # stale records plus unused local images
kinhin doctor                              # disk headroom and image warnings
```

In the app, the macOS card's **More images** (under **Advanced → Capacity**) has one entry per named image with its
base-image picker, status, **Prepare**, **Rebuild…** and **Remove**; a changed `base_image` only takes effect after a
rebuild. A macOS bake runs in a scratch VM and swaps the image in at the end, so a failed or cancelled one leaves the
previous image working ([Cancelling a build](https://kinhin.dev/guide/runtimes.md#cancelling-a-build)).

## Not verified

These are example recipes, not a tested matrix. What this repository's own CI exercises is the headless Android
emulator boot on a `kinhin-xcode` Tart runner for store screenshots (`.github/workflows/video.yml`, recorded in
[Store screenshots](https://kinhin.dev/guide/mobile-screenshots.md#what-is-verified)); the Apple-platform downloads, the browser and
mobile-release macOS images and the Linux browser and x64 pools were not run as part of writing this page. Check one
job on each new image before you route a whole workflow to it.
