CI
Ant is a single binary, so a CI job is three steps: install it, sign in with a
ci-role account, and deploy. Nothing prompts, and every failure exits
non-zero.
One-time setup
- Invite the pipeline's account with the
cirole.cican deploy, roll back, and read status and logs; it cannot change the roster, read the audit log, or hold OS accounts.ant colony invite --role ci --machine prod # or, once the account's NodeID is known: ant colony users add <nodeid> --machine prod --role ci
The pipeline needs its own account identity: sign up once, redeem the invite, then export it.ant colony signup --name ci ant colony join --token "$(cat invite.txt)" --alias prod ant colony export --out ant-ci.json - Store the bundle and passphrase as CI secrets: the bundle file as
ANT_BUNDLEand its passphrase asANT_PASSPHRASE(masked). - Register the machine so the runner can dial it. The NodeID comes from
ant nest bootstrap's output orant nest identity showon the machine:ant nest machines add prod --hostname prod.example.com --node-id <nodeid>
Dialing is by NodeID;--hostnameis only a label for the machine (it does not have to resolve from the runner), so the NodeID is the part that matters.
GitHub Actions
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
env:
ANT_MACHINE: prod
ANT_PASSPHRASE: ${{ secrets.ANT_PASSPHRASE }}
steps:
- uses: actions/checkout@v6
- name: Install ant
run: |
curl -fsSL https://ants-docs.pages.dev/dl/install.sh | sh
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Sign in
env:
ANT_BUNDLE: ${{ secrets.ANT_BUNDLE }}
run: |
printf '%s' "$ANT_BUNDLE" > /tmp/ant-ci.json
ant colony login --bundle /tmp/ant-ci.json
- name: Register the machine
run: ant nest machines add prod --node-id "${{ vars.ANT_MACHINE_NODE_ID }}"
- name: Deploy
run: ant trail deploy --release "$GITHUB_SHA" --json | tee deploy.json
GitLab CI
deploy:
stage: deploy
# glibc, not Alpine: the release binary links glibc dynamically. The
# docker.io package provides the CLI used for source builds; skip it if the
# project deploys a prebuilt image.
image: debian:bookworm-slim
services: [docker:27-dind]
variables:
ANT_MACHINE: prod
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
script:
- apt-get update && apt-get install -y --no-install-recommends curl ca-certificates docker.io
- curl -fsSL https://ants-docs.pages.dev/dl/install.sh | sh
- export PATH="$HOME/.local/bin:$PATH"
- printf '%s' "$ANT_BUNDLE" > /tmp/ant-ci.json
- ant colony login --bundle /tmp/ant-ci.json
- ant nest machines add prod --node-id "$ANT_MACHINE_NODE_ID"
- ant trail deploy --release "$CI_COMMIT_SHA" --json
only: [main]
ANT_PASSPHRASE, ANT_BUNDLE, and ANT_MACHINE_NODE_ID are masked CI
variables. The install script and the release downloads need no credentials.
A runner with Docker is only needed for source builds and for compose projects
that must resolve locally (build services, image_signing, references outside
the project directory, or variables only the runner's environment defines). A
project with deploy.build: none (or the --image form) builds nothing
locally, and a no-build compose project is resolved on the machine — both
deploy from a runner without Docker.
Split build and deploy
Build once in a fast job, push to the registry, and deploy in another job that needs neither the source nor a local build:
# job A, needs deploy.registry in ant.yaml and ANT_REGISTRY_PASSWORD
ant haul --push --release "$GITHUB_SHA"
# job B, runs the pushed image on the machine; set ANT_REGISTRY_USERNAME and
# ANT_REGISTRY_PASSWORD here too, and the pull credential travels with the deploy
ant trail deploy --image ghcr.io/org/app:"$GITHUB_SHA" --pull --machine prod
For a private image, job B either sets ANT_REGISTRY_USERNAME +
ANT_REGISTRY_PASSWORD (the credential rides the deploy to the machine and is
gone when it finishes) or the machine carries its own docker login.
ant haul --push always builds on the runner (the image must exist there to be
pushed) and supports container projects; compose projects push their service
images with docker.
Reading the result
--json prints the deploy or rollback result on stdout while build output
stays on stderr, so a pipeline can consume it directly:
release=$(ant trail deploy --json | jq -r .release)
ant trail rollback --to "$release" --json
Fields: app, deployment, machine, runner, builder, image,
release, container, compose, routes, warnings.
Rollback from CI
ant trail rollback --to "$PREVIOUS_RELEASE" --json
rollback.keep_releases (or deploy.keep_images) controls how many container
releases stay on the machine; the target image tag must still exist there. For a
remote compose or stack project the worker stores a release record for each
deploy, and rollback re-applies it (see
Compose and stack rollback).
Notes
- The runner needs a Linux amd64/arm64 build with CGO; the release binaries are. The macOS/Windows CLI builds run local-first and cannot reach a machine.
- The runner needs outbound UDP and DNS for iroh (relay and address lookup) and HTTPS for the install script. No inbound port is required.
--hostnameonmachines addis only a label; machines are dialed by NodeID, so the runner never connects to that name.ANT_MACHINEis the environment fallback for--machine, so a pipeline sets the target once.- Worker and CLI must speak the same protocol version. Update the worker with
ant nest worker update --machine prod; a machine provisioned before self-update support needs one re-provision over SSH (see Known issues).
Scoping the credential in time
Two ways to keep a CI credential from living forever:
Expiring membership. Have the pipeline join with a time-limited grant; the daemon stops authorizing it at the deadline:
# On the machine, invite the pipeline's account with a 30-day membership:
ant colony invite --role ci --machine prod --ttl 1h --grant-ttl 720h
Or set the deadline on an existing member:
ant colony users add <nodeid> --machine prod --role ci --expires-in 720h
ant colony users list shows the expiry. Re-granting is one command.
Workload identity: no stored secret
OIDC workload identity removes the bundle from CI entirely. Configure the rule once per machine:
ant colony oidc set --machine prod \
--issuer https://token.actions.githubusercontent.com \
--jwks https://token.actions.githubusercontent.com/.well-known/jwks \
--audience ant --repo your-org/your-repo --ref refs/heads/main \
--role ci --max-ttl 1h
The rule matches the token's repository (or GitLab's project_path) and
ref claims, with trailing * as a prefix pattern. Then each job creates a
throwaway account and joins with the provider's token — nothing long-lived is
stored:
# GitHub Actions job
permissions:
id-token: write
steps:
- run: curl -fsSL https://ants-docs.pages.dev/dl/install.sh | sh
- run: ant colony signup --name ci
- run: ant colony join --oidc --github --machine prod
- run: ant trail deploy --release "$GITHUB_SHA" --json
--github requests a token from the runner (audience from --audience,
default ant). Any provider's token can be passed instead with --oidc-token
or ANT_OIDC_TOKEN. The daemon verifies the signature against the issuer's
JWKS, checks the audience/repository/ref, and registers the ephemeral NodeID
with ci until the token expires (capped by --max-ttl).
Rotating a bundle-based account
If you still use a bundle, rotation means issuing a new account: remove the old
member (ant colony users remove <old-nodeid> --machine prod), sign up, join
with a short-lived invite, export, and replace the CI secret:
ant colony signup --name ci
ant colony join --token "$(cat invite.txt)" --alias prod
ant colony export --out ant-ci.json
The bundle itself never expires; scope the resulting membership with
--grant-ttl or switch the pipeline to OIDC (see
Known issues).