npx levelrail-cli@<version> <command> or npm install --global levelrail-cli@<version> (details). It is the client only, not the server.
The three steps
- Install the CLI in the job, or call the API directly. The installer is
curl -fsSL https://levelrail.com/install-cli.sh | sh. SetLEVELRAIL_CLI_INSTALL_DIRto a directory you can write to (the default is/usr/local/binfor root and~/.local/binotherwise) andLEVELRAIL_VERSION=vX.Y.Zto pin a release. - Authenticate with environment variables only.
LEVELRAIL_API_URLis your control plane URL andLEVELRAIL_TOKENis an API token with at least thedeployability.LEVELRAIL_PROFILEpicks a saved profile and is not needed in CI. The CLI also readsCI=true(orLEVELRAIL_CI=true) and then never prompts, and it does so by itself when stdin or stdout is not a terminal. - Deploy by image, then wait.
apps deployreturns as soon as the deploy is accepted.apps waitis what tells you whether the rollout worked.
apps deploy requires --image here; add --confirm to deploy into a protected environment. apps wait also takes --attempt-id and --poll-interval (default 3s).
On GitHub Actions, GitLab CI and CircleCI you can skip the stored token and use OIDC instead. Elsewhere, create the token once and store it in your CI’s secret store:
Least-privilege token
When you cannot use OIDC, give the CI the smallest token that can deploy. Thedeployer preset grants read and deploy only, so the token cannot read secrets or change settings. Add a short expiry and, if you use teams, limit it to one project:
LEVELRAIL_TOKEN and rotate it before it expires. See Teams and roles for what a scope allows.
Roll back on failure
apps wait exits 5 when the deploy converged as a failure and 6 on timeout. To go back to the previous successful deploy, run this in a step that only runs when the deploy step failed:
--image, apps rollback picks the newest earlier successful deploy. It returns as soon as the request is accepted, so check apps status to see that it landed. In a shell script:
if: failure() on a step after the deploy step. On GitLab CI use after_script or a job with when: on_failure. On CircleCI use when: on_fail. On Jenkins use post { failure { ... } }. On Buildkite run the script above in the same step. Rolling back needs the same deploy ability as deploying.
Exit codes
Branch on these in scripts.
A job running
apps deploy then apps wait fails on any non-zero code, which is what you want.
Safe retries
apps deploy sends an Idempotency-Key, so re-running the same job applies the deploy once and replays the first result. The CLI derives the key from the app, the image and the run id. It reads only two sets of run variables: GITHUB_RUN_ID with GITHUB_RUN_ATTEMPT, and CI_PIPELINE_ID (set by GitLab CI). On any other CI it falls back to the current minute, so pass your own key from the CI’s build id:
Retry-After. LEVELRAIL_RETRY_MAX (default 3, 0 turns retry off) and LEVELRAIL_RETRY_MAX_WAIT (default 60s) bound it. See Deploy from your computer.
Ready-to-copy pipelines
Each file builds an image, pushes it, deploys it pinned by digest and waits for the rollout to be healthy. A test in the CLI parses every file and fails if a command or flag it uses no longer exists, so they stay current.
Each file needs a CI trust on the app once (see OIDC support). The job then runs
levelrail-cli apps ci token my-app --provider <github|gitlab|circleci>, which swaps the job’s identity token for a deploy token that expires after 15 minutes. On GitLab and CircleCI the token is read from LEVELRAIL_ID_TOKEN, or from the variable named by --id-token-env. apps github-actions token and apps github-actions trust still work as deprecated aliases of apps ci token and apps ci trust.
Deploy by digest from a build-complete hook
If your CI already built and pushed the image and you would rather call the API than install the CLI, send the deploy straight to the same endpointapps deploy uses. There is no separate webhook to set up:
imagetakesname:tag,name@sha256:digestorname:tag@sha256:digest. Pin by digest so a re-pushed tag can never change what runs.- The token needs the
deployability on the app, the same as the CLI. An OIDC exchange token from GitHub, GitLab or CircleCI works here too. - The
Idempotency-Keymakes a retried hook apply once: a repeat with the same key and body within 24 hours replays the first response, and the same key with a different body is refused. - Deploy freezes, protected environment approvals (add
"confirm": true), deploy policies and rate limits apply exactly as they do to any other deploy, and the call is recorded in the audit log. - A
202means accepted. PollGET /api/v1/apps/my-app/deploy-attempts, or runlevelrail-cli apps wait my-app, to learn whether it became healthy.
levelrail-cli apps deploy my-app --image registry.example.com/team/my-app@sha256:<digest>.
OIDC support
A CI trust lets one pipeline identity deploy one app. The exchange endpoint (POST /api/v1/ci/oidc-exchange) verifies the job’s identity token, finds a trust on the app that matches it, and returns a token that can only read and deploy that app for 15 minutes. With no matching trust the answer is 403 and nothing is granted.
POST /api/v1/apps/{name}/ci/trusts as provider, issuer, org_id, repository, ref_pattern, environment and protected_ref_only.
How tokens are checked:
- Issuers are an allowlist. GitHub’s issuer is fixed. A GitLab or CircleCI token is only considered when its
issequals, exactly, the issuer of a trust on that app (https://gitlab.com, your self-managed URL, orhttps://oidc.circleci.com/org/<ORG_ID>). Keys are fetched from that configured issuer (<issuer>/oauth/discovery/keyson GitLab,<issuer>/.well-known/jwks-pub.jsonon CircleCI), never from a URL inside the token. - Audience. The token’s
audmust be the dashboard URL set in Settings. Set it inid_tokenson GitLab, and withcircleci run oidc get --claims '{"aud":"..."}'on CircleCI (the default CircleCI token’s audience is the organization ID, which is refused). - Signatures. Only RS256 and ES256 are accepted, the token must name its key with
kid, andexp,nbfandiatare checked. - Key fetching uses https only, refuses hosts that resolve to private, loopback or link-local addresses, does not follow redirects to other hosts, and refetches on an unknown key at most once per refresh interval.
- GitLab safe defaults. A GitLab trust accepts only protected branches and tags (
ref_protected), unless it is created with--no-protected-ref(API:"protected_ref_only": false); the response then carries a warning, because any developer who can push a matching branch or tag could deploy. Pipelines withpipeline_sourcemerge_request_eventorexternal_pull_request_eventare always refused, since a merge request from a fork can run in the parent project with its project path and a branch namedmain. When the trust names an environment, the token must also carryenvironment_protected: true, because any job can declare an environment. - Who may add a trust. The caller needs
write:sensitiveanddeployon the app, so a trust never grants more than its creator holds. A self-managed GitLab issuer (anything other thanhttps://gitlab.com) needs a root user, since whoever runs that issuer can mint tokens. - Token age. Tokens older than
APP_CI_OIDC_MAX_TOKEN_AGE(default1h) are refused, and so are tokens withoutiatwhile a maximum age applies. - Audit. Trust create and delete write
ci_oidc_trust.createdandci_oidc_trust.deletedaudit entries with the provider and issuer. Every issued token writesci_oidc_exchange.issued; refusals writeci_oidc_exchange.refusedwith the reason, at most one row per app, provider and reason perAPP_CI_OIDC_AUDIT_WINDOW(default1m, with a suppressed count). Entries carry the app, provider and a hash of the subject, never the token. - Logs carry the app, the trust ID and a shortened subject, never the token.
These variables apply to GitLab and CircleCI. GitHub tokens are verified as before. Buildkite OIDC is not accepted yet; use an API token there.
Stacks
Stack trusts (POST /api/v1/stacks/{name}/oidc-trusts, root only) take the same provider, issuer, org_id and protected_ref_only fields and the same checks as app trusts, for plan and apply from GitLab CI and CircleCI. An apply trust additionally needs an exact branch or tag ref and an environment (a protected one on GitLab), and a GitLab apply trust always requires protected refs; a plan-only GitLab trust may opt out and then returns the warning. Merge request pipelines are refused. Create and exchange write stack.oidc_trust_create and stack.oidc_exchange audit entries with the provider and issuer. Stack trusts have no CLI command yet; use the API.
Downgrading
Rolling back to v0.8.8 or earlier makes the older control plane ignore theprovider column, so it would treat a GitLab or CircleCI trust row as a GitHub trust on the same path. Delete every non-GitHub trust (apps ci trust list then trust remove) before you downgrade.
GitLab CI
SetLEVELRAIL_API_URL under Settings > CI/CD > Variables (not a secret). Add the trust once, then request an ID token for the control plane in the job.
CI_PIPELINE_ID is read for the idempotency key, so no extra flag is needed. The control plane must be able to pull $IMAGE, so add the registry credentials to the app first. To keep using an API token instead, store it as a masked, protected variable LEVELRAIL_TOKEN and drop the id_tokens block and the token lines.
CircleCI
PutLEVELRAIL_API_URL in a context (here levelrail) and require that context’s ID in the trust with --environment.
Jenkins
Create two Secret text credentials with the idslevelrail-api-url and levelrail-token under Manage Jenkins > Credentials. The complete Jenkinsfile is ci-examples/token/jenkins.groovy; the dashboard shows the same file for your app under Deploy settings, and levelrail-cli apps ci template my-app jenkins prints it.
The single-quoted sh strings keep Groovy from interpolating the secrets into the command line, and Jenkins masks the credential values in the log.
Buildkite
Keep the secrets in your agent environment hook, a secrets manager plugin, or Pipeline Settings. Do not put them inpipeline.yml. The complete pipeline is ci-examples/token/buildkite.yml; levelrail-cli apps ci template my-app buildkite prints it for your app.
$$ stops Buildkite from expanding the variable at upload time. LEVELRAIL_API_URL and LEVELRAIL_TOKEN must already be in the step’s environment.
Troubleshooting
Next steps
- Deploying from GitHub Actions: the OIDC, no stored secret path.
- CLI reference:
apps deployandapps waitin full. - Identity and access: token abilities and presets.