GitLab Runner executor to run jobs in Tart VMs
GitLab Runner executor to run jobs in Tart VMs
Custom GitLab Runner executor to run jobs inside ephemeral Tart macOS virtual machines.
[!IMPORTANT]
macOS 15 (Sequoia) or later
In case you've upgraded and encountering an issue below:
Waiting for the VM to boot and be SSH-able...The newly introduced "Local Network" permission in macOS Sequoia requires accepting a GUI pop-up on each host machine that runs the GitLab Tart Executor.
To work around this, there are two options. The first one is to modify your GitLab Runner configuration to invoke the
gitlab-tart-executorbinary asroot, with an additional--usercommand-line argument, which takes the name of your regular, non-privileged user on the host machine.This will cause the GitLab Tart Executor to start a small
gitlab-tart-executor localnetworkhelperprocess in the background and then drop the privileges to the specified user.This helper process is privileged and is needed to establish network connections on behalf of the GitLab Tart Executor without triggering a GUI pop-up.
This approach is more secure than simply running
gitlab-tart-executorasroot, because only a small part of the program runs privileged, and the only functionality that this part is performing is establishing new connections.The second workaround is to set the local network privacy preferences so that all IPv4 private address space that could potentially be used for VMs is excluded:
sudo defaults write com.apple.network.local-network AllowedEthernetLocalNetworkAddresses -array "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16" sudo defaults write com.apple.network.local-network AllowedWiFiLocalNetworkAddresses -array "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16"...and then reboot.
brew install cirruslabs/cli/gitlab-tart-executorconcurrent = 2
[[runners]]
# ...
executor = "custom"
[runners.feature_flags]
FF_RESOLVE_FULL_TLS_CHAIN = false
[runners.custom]
config_exec = "gitlab-tart-executor"
config_args = ["config"]
prepare_exec = "gitlab-tart-executor"
prepare_args = ["prepare"]
run_exec = "gitlab-tart-executor"
run_args = ["run"]
cleanup_exec = "gitlab-tart-executor"
cleanup_args = ["cleanup"]To use the "Local Network" helper process (see the note in the beginning of this README.md), additionally modify the prepare and run stages as follows:
concurrent = 2
[[runners]]
# ...
executor = "custom"
[runners.feature_flags]
FF_RESOLVE_FULL_TLS_CHAIN = false
[runners.custom]
config_exec = "gitlab-tart-executor"
config_args = ["config"]
prepare_exec = "sudo"
prepare_args = ["-E", "gitlab-tart-executor", "prepare", "--user", "$USER", "--concurrency", "2", "--cpu", "auto", "--memory", "auto"]
run_exec = "sudo"
run_args = ["-E", "gitlab-tart-executor", "run", "--user", "$USER"]
cleanup_exec = "gitlab-tart-executor"
cleanup_args = ["cleanup"]And replace the $USER with the name of your regular, non-privileged user on the host machine.
Now you can use Tart Images in your .gitlab-ci.yml:
# You can use any remote Tart image.
# Tart Executor will pull it from the registry
# and use it for creating ephemeral VMs.
image: ghcr.io/cirruslabs/macos-ventura-base:latest
test:
# In case you tagged runners that have
# GitLab Tart Executor configured on them
tags:
- tart-installed
script:
- uname -aIt's been noted that jobs run faster when they write to a volume mounted from the host (most likely because this avoids the copy-on-write expansion of the VM's disk).
Tart Executor will mount a temporary directory from the host automatically if you set the TART_EXECUTOR_HOST_DIR variable either in GitLab UI or in .gitlab-ci.yml:
test:
# You can use any remote Tart image.
# Tart Executor will pull it from the registry
# and use it for creating ephemeral VMs.
image: ghcr.io/cirruslabs/macos-ventura-base:latest
# In case you tagged runners that have
# GitLab Tart Executor configured on them
tags:
- tart-installed
script:
- uname -a
variables:
TART_EXECUTOR_HOST_DIR: "true"You can tell the Tart Executor to override the default CPU and memory settings of the VM image by passing the --cpu and --memory command-line arguments to prepare sub-command.
To avoid manually retrieving and calculating the total number CPUs and the memory on the host, pass the auto as an argument to --cpu and --memory instead of the numerical values, e.g. --cpu auto or --memory auto.
This will force the prepare stage to retrieve the total host resources internally and calculate them according to formula:
/ ...where `` is controlled by the --concurrency command-line argument.
Here's an example on how to configure the GitLab Runner to run two Tart VMs concurrently, utilizing half of the host's resources for each VM:
concurrent = 2
[[runners]]
# ...
executor = "custom"
[runners.feature_flags]
FF_RESOLVE_FULL_TLS_CHAIN = false
[runners.custom]
config_exec = "gitlab-tart-executor"
config_args = ["config"]
prepare_exec = "gitlab-tart-executor"
prepare_args = ["prepare", "--concurrency", "2", "--cpu", "auto", "--memory", "auto"]
run_exec = "gitlab-tart-executor"
run_args = ["run"]
cleanup_exec = "gitlab-tart-executor"
cleanup_args = ["cleanup"]Tart Executor uses the default admin:admin credentials when connecting to the VM over SSH.
If your image uses different credentials, set TART_EXECUTOR_SSH_USERNAME and/or TART_EXECUTOR_SSH_PASSWORD variables either in GitLab UI or in .gitlab-ci.yml:
test:
# You can use any remote Tart image.
# Tart Executor will pull it from the registry
# and use it for creating ephemeral VMs.
image: ghcr.io/cirruslabs/macos-ventura-base:latest
# In case you tagged runners that have
# GitLab Tart Executor configured on them
tags:
- tart-installed
script:
- uname -a
variables:
TART_EXECUTOR_SSH_USERNAME: "custom-username"
TART_EXECUTOR_SSH_PASSWORD: "custom-password"Tart Executor is open sourced under MIT license so people can base their own executors in Go of this code. Tart itself on the other hand is source available under Fair Software License that required paid sponsorship upon exceeding a free limit.
config stage| Argument | Default | Description |
|---|---|---|
--builds-dir |
Path to a directory on host to use for storing builds, automatically mounts that directory to the guest VM (mutually exclusive with --guest-builds-dir) |
|
--cache-dir |
Path to a directory on host to use for caching purposes, automatically mounts that directory to the guest VM (mutually exclusive with --guest-cache-dir) |
|
--guest-builds-dir1 |
Path to a directory in guest to use for storing builds, useful when mounting a block device (via --disk command-line argument) to the VM (mutually exclusive with --builds-dir) |
|
--guest-cache-dir1 |
Path to a directory in guest to use for caching purposes, useful when mounting a block device (via --disk command-line argument to the VM (mutually exclusive with --cache-dir) |
1: this is an advanced feature which should only be resorted to when the standard directory sharing via --builds-dir and --cache-dir is not sufficient for some reason.
prepare stage| Argument | Default | Description |
|---|---|---|
--concurrency |
1 | Maximum number of concurrently running Tart VMs to calculate the auto resources |
--cpu |
no override | Override default image CPU configuration (number of CPUs or auto1) |
--memory |
no override | Override default image memory configuration (size in megabytes or auto1) |
--dir |
--dir arguments to pass to tart run, can be specified multiple times |
|
--disk |
--disk arguments to pass to tart run, can be specified multiple times |
|
--auto-prune |
true | Whether to enable or disable the Tart's auto-pruning mechanism (sets the TART_NO_AUTO_PRUNE environment variable for Tart command invocations under the hood) |
--allow-image |
only allow running images that match the given doublestar-compatible pattern, can be specified multiple times | |
--default-image |
A fallback Tart image to use, in case the job does not specify one | |
--nested |
false | Run VMs with nested virtualization enabled |
--tart-run-env |
Environment variable overrides for tart run |
|
--user |
username to drop privileges to (see the note in the beginning of this README.md about "Local Network" helper process) |
run stage| Argument | Default | Description |
|---|---|---|
--user |
username to drop privileges to (see the note in the beginning of this README.md about "Local Network" helper process) |
1: automatically distributes all host resources according to the
No open issues yet, or sync has not completed.