Manifest-driven Coolify reconciler - rig builds the boxes, cast fills them
Find a file
claude-hdb 30e74fbc1e fix: restore-db.sh takes the target database name — objects landed in the maintenance DB
psql -U postgres with no -d restores into the 'postgres' maintenance
database unless the app DB happens to carry that name. Fourth required
argument passes -d <db-name>; ON_ERROR_STOP=1 so a mid-stream failure
aborts instead of half-restoring silently.

Found by the prod-migration plan final review (finding #6); drilled in
Task 9 before cutover day.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 20:25:14 +00:00
.github/workflows feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
bin feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
docs docs: add semantics.md — the apply contract and Coolify 4.1.2 limits 2026-07-11 13:13:19 +00:00
reference feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
scripts fix: restore-db.sh takes the target database name — objects landed in the maintenance DB 2026-07-11 20:25:14 +00:00
src feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
test feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
.gitignore feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
biome.jsonc feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
install.sh fix(install): wire BINDIR onto PATH in the shell profile, not a warning 2026-07-11 15:12:14 +00:00
package-lock.json feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
package.json feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
README.md fix(install): wire BINDIR onto PATH in the shell profile, not a warning 2026-07-11 15:12:14 +00:00
tsconfig.json feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00
vitest.config.ts feat: cast — the Coolify executor, extracted from the infra state repo 2026-07-11 12:25:44 +00:00

cast

Point it at a repo and a state directory; it makes a Coolify instance match what the repo declares. One-way, idempotent, never deletes.

Philosophy (shared with rig and claudebox): public tool, private state. cast holds no hostnames, no bindings, no secrets, nothing about your infrastructure. It reads what you point it at and stores nothing, ever.

rig builds the boxes. cast fills them.

Install

curl -fsSL https://raw.githubusercontent.com/heavy-duty/cast/main/install.sh | bash

Needs node >= 22.12 and age (secrets are decrypted by shelling out to it). Re-run any time to upgrade. Unlike rig — which is pure bash so it can run on a bare box — cast runs on your machine: it is an API client, and a server should never install it.

The installer symlinks cast into ~/.local/bin (or /usr/local/bin as root) and, if that directory is not already on your PATH, appends it to your shell profile — .zshrc, .bashrc/.bash_profile, or config.fish, whichever your $SHELL reads — marked # added by cast-install and written only once. The shell you ran the installer from does not inherit it (a curl | bash pipeline is a subshell), so open a new shell or source the profile it names. Set CAST_NO_MODIFY_PATH=1 to be left alone and wire PATH yourself.

The two inputs

cast joins a manifest (what to deploy) with state (where, and with what values). Neither knows about the other, which is the whole point: a manifest can live in a product repo without leaking your infrastructure, and your infrastructure can be re-pointed at a new Coolify without touching a product.

1. The product repo's .infra/ — committed, instance-blind:

.infra/
  manifest.yaml                  # applications, databases, services, per environment
  env/<app>.<env>.env.template   # var NAMES + non-secret values; ${SECRET} placeholders

2. A state directory — private, yours:

environments.yaml               # bindings: which server each env deploys onto, the S3
                                #   destination, GitHub App name, smoke target, guards
secrets/<repo>.<env>.env.age    # age-encrypted values for the ${…} placeholders
.coolify.env                    # COOLIFY_BASE_URL + COOLIFY_ACCESS_TOKEN (never commit)

Pass it with --state <dir>, or set CAST_STATE. Defaults to the cwd.

Commands

cast apply <org>/<repo> --env <env> [--path <dir>] [--hostname-overlay <file>]
cast diff  <org>/<repo> --env <env> [--full]
cast server add <name> --ip <ip> --key <file> [--user root] [--port 22]
cast smoke
  • apply — idempotent create-or-update of every manifest resource, then redeploy what changed. One-way: it never deletes a resource that Coolify has and the manifest doesn't. Clones the repo's default branch unless --path points at a local checkout (refused with --env prod — prod always reads the default branch).
  • diff — reports drift, manifest → Coolify. Structural by default; --full also compares env vars. Exits non-zero when dirty, so CI can gate on it.
  • server add — uploads a server's private key and registers it with Coolify.
  • smoke — contract test against smoke_target: proves Coolify's bulk env endpoint still upserts rather than replacing. Run it after every Coolify upgrade — apply's never-delete guarantee rests on that behavior, and the published OpenAPI does not describe it accurately.

--hostname-overlay swaps domains for a pre-flight run against temporary hostnames; re-applying without it is the cutover.

docs/semantics.md is the contract behind those commands: what apply guarantees (never deletes, never recreates a database, fails loudly rather than recreating on un-updatable drift), the dockercompose build pack, the hostname-overlay shapes, and the places Coolify 4.1.2 does not cooperate — each citation verified against coollabsio/coolify v4.1.2 and the vendored OpenAPI in reference/. Read it before changing apply.

Secrets, and attended applies

An environment's age identity is resolved in exactly two ways:

  1. $CAST_AGE_KEY_FILE_<ENV> — injected for this invocation
  2. ~/.config/cast/age-<env>.key — a standing key on this machine

That is the whole mechanism behind attended vs unattended applies: an environment whose key you never leave on disk can only be applied by someone who injects it. Keep a standing key for staging if you like; keep prod's in a password manager and pass it per apply.

The state directory holds ciphertext. It must never hold the identity that opens it.

Guarding an environment

An environment may refuse variables by name pattern:

environments:
  prod:
    server: prod-box
    forbidden_var_patterns: ["^ALLOW_"]

apply then refuses if any such var is present on any resource, regardless of value. ALLOW_SEED=false still fails: a var that exists can be flipped on later in the Coolify UI without touching a manifest, so "off" has to mean absent.

This guard lives in your private state deliberately — not in the product's manifest. A product-side change must not be able to lower its own guard.

Scripts

Operational helpers, all argument-driven (scripts/): register a GitHub App with Coolify, dump the Coolify control-plane database age-encrypted to S3, restore a database backup into a target container.

Development

npm ci && npm run build && npm test
npm run check          # biome