Deploy an app
Deploy a tag
Section titled “Deploy a tag”Push the image to the registry your app pulls from, then deploy its tag:
leaf app deploy web 4f2c1a9The tag is the value the compose file’s ${APP_TAG} becomes, so the image
ghcr.io/<owner>/web:4f2c1a9 must exist. A tag is 1 to 128 letters, digits, dots, dashes or
underscores. It cannot be rollback or start with a dash or a dot.
Without --wait, the command queues the deploy and prints its ID:
Deploy dep-a1b2c3d4e5f6 queued for web
Follow it: leaf app deploy-log web dep-a1b2c3d4e5f6Set the image
Section titled “Set the image”Before the first deploy, tell the app which image to run and which port it listens on:
leaf app image web ghcr.io/acme/web --port 8080 --health /healthzThe image is a repository reference without a tag or digest; the tag comes from the
deploy command. --port is between 1 and 65535 and --health starts with /. The app
host writes a compose file with one web service from these values. If the image is
private, name a saved credential with --registry <name>:
leaf app image web ghcr.io/acme/web --registry ghcr --port 8080 --health /healthzHealth check
Section titled “Health check”The server decides that an app is up in one of two ways:
- TCP (the default when you give no path): the server opens a connection to the app’s port. The check passes when the port accepts it. The app is not asked for anything, so a database or other service that is down cannot make a healthy app look broken, and a good deploy is not rolled back because of it.
- HTTP (
--health /healthz): the server requests that path and passes on any2xxanswer. Redirects do not count.
Keep an HTTP health endpoint shallow: it should answer 200 once the process is running, and
it should not call a database or any other dependency. If it does, an outage in that dependency
marks the app down, and a deploy that would have worked is rolled back. TCP avoids that; use HTTP
only when you need the app itself to answer.
Choose the check when you create the app, or change it later without a deploy:
leaf app create web --preset nano --health-check tcpleaf app set web --health-path /healthzleaf app set web --health-check tcpleaf app show web prints the check, for example HTTP GET /healthz or TCP port 8080.
Registry credentials
Section titled “Registry credentials”Save a username and password/token once per account; the value is read from standard input and is never shown again or stored in plain text:
echo "$GHCR_TOKEN" | leaf app registry add ghcr --server ghcr.io --username acme --password-stdinleaf app registry listleaf app registry remove ghcrlist shows the name, server, username and when the credential was last used, never the
secret. --server is a host such as ghcr.io (no scheme or path). Any registry that
uses a username and password/token login works.
For a one-off deploy you can skip saving the credential and pipe it straight into the
deploy with --registry-token-stdin:
echo "$GHCR_TOKEN" | leaf app deploy web "$SHA" --wait --registry-token-stdinIt is used for that deploy only and is not saved on the account.
Wait for the result
Section titled “Wait for the result”leaf app deploy web 4f2c1a9 --wait--wait asks the server for the deploy’s state every few seconds, for up to 55 minutes. It prints the
result and the last lines of the server’s output, and exits 0 only when the deploy succeeded. Use it in
CI so the job fails when the app does not come up.
✓ Deploy dep-a1b2c3d4e5f6 succeeded
OK running=4f2c1a9What happens on a failed deploy
Section titled “What happens on a failed deploy”The server starts the new tag, then runs the app’s health check. The deploy states are queued,
running, succeeded, failed and rolled_back.
- Health check fails: the server starts the previous tag again. The deploy is recorded as
rolled_back, and the app keeps running the previous tag.leaf app deploy … --waitexits1withDeploy <id> failed and the server rolled back. The app is still on its previous tag. - Another failure, such as the image not being found or the compose file being refused: the deploy is
recorded as
failed.--waitexits1. - A first deploy has no previous tag, so it cannot roll back; a failure leaves it
failed.
To see what happened:
leaf app deploys webleaf app deploy-log web dep-a1b2c3d4e5f6leaf app deploys lists the newest deploy first, with its ID, action, tag, state and time.
leaf app deploy-log prints that deploy’s output.
Only one deploy runs per app at a time. A second request while one is queued or running is refused with
A deploy of this app is already queued or running, and the account may request 30 deploys and
rollbacks an hour.
Roll back
Section titled “Roll back”leaf app rollback webleaf app rollback web --waitWithout an ID this switches the app to its previous tag. Add --to <deploy id> to return
to any earlier successful deploy, as long as its image is still in the registry:
leaf app rollback web --to dep-a1b2c3d4e5f6 --waitYou can roll back to the same deploy any number of times. Add --restore-variables to
also restore the environment variables that deploy ran with. The target must be a
successful deploy of this app; the ID is listed by leaf app deploys web. With no
previous tag, a rollback without --to is refused with
This app has no previous tag to roll back to.
Settings in leaf.toml
Section titled “Settings in leaf.toml”An app project may put its own settings next to the static-site ones in leaf.toml:
[app]name = "flair-api" # which app `leaf app deploy` targets when no app is givensleep_after = "1h" # "5m".."24h", "never", or "default" (the tier default)namelets a deploy run without repeating the app name. A name on the command line wins. Because the first positional is always the app, pair the tag with the flag:leaf app deploy --tag 4f2c1a9(orleaf app deploy --redeploy).sleep_afteris validated locally before any network call, with the same rule the API applies:"5m"to"24h","never", or"default". The deploy stores it; the error names theapp.sleep_afterkey when the value is wrong.- A field that is not in the file is not sent, so a deploy never undoes a value set in the
dashboard or by an earlier deploy. Write
"default"to go back to the tier default.
Static-site projects are unaffected: without an [app] table, leaf.toml means exactly what
it meant before.
An app is created in a tier: economy (the default), standard or dedicated. The tier is
where the app runs and what it is for, and it is fixed at create:
leaf app create api --preset small --tier standardEach tier has a default idle time after which the app may sleep. leaf app show prints the
app’s tier and its effective sleep time, and whether that comes from the app or the tier
default.
Check the app
Section titled “Check the app”leaf app listleaf app show webleaf app list shows each app’s name, current tag, domain and last deploy state. leaf app show web
shows its domain, running tag, previous tag, tier, sleep setting and last deploy.
Deploy from GitHub Actions
Section titled “Deploy from GitHub Actions”With OIDC there is no LeafCloud secret to store. Trust the repository once, then give the
deploy job id-token: write and packages: read. This workflow builds and pushes the
image with the commit SHA as its tag, then deploys it:
name: deployon: push: branches: [main]permissions: contents: readjobs: build: runs-on: ubuntu-latest permissions: { contents: read, packages: write } steps: - uses: actions/checkout@v4 - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push run: | IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}" docker build -t "$IMAGE:$GITHUB_SHA" . docker push "$IMAGE:$GITHUB_SHA" deploy: needs: build runs-on: ubuntu-latest permissions: { id-token: write, packages: read } steps: - run: curl -fsSL https://leafcloud.in/install.sh | sh - run: echo "${{ secrets.GITHUB_TOKEN }}" | leaf app deploy web ${{ github.sha }} --wait --registry-token-stdinSet it up with leaf ci trust github <owner>/<repo> --app web, and manage trusted
repositories with leaf ci list and leaf ci untrust <id>. OIDC tokens are short-lived
and bound to that one app. See Deploy from CI for details and for
the API-key alternative.
Deploy from other CI providers with an API key
Section titled “Deploy from other CI providers with an API key”Create an API key with the apps scope. It can deploy and roll back every app on the account, and
nothing else: it cannot deploy static sites or manage databases, and it cannot be limited to one app.
leaf keys create --name github-deploy --can apps --expires 90dYou can also create this key in the dashboard under Settings → API keys → Create API key with the Deploy apps preset.
Store the secret as LEAF_TOKEN in the repository. This GitHub Actions workflow pushes the image with
the commit SHA as its tag, then asks LeafCloud to deploy it:
name: deployon: push: branches: [main]permissions: contents: read packages: writejobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push run: | IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}" docker build -t "$IMAGE:$GITHUB_SHA" . docker push "$IMAGE:$GITHUB_SHA" - name: Install the leaf CLI run: | curl -fsSL https://leafcloud.in/install.sh | sh echo "$HOME/.local/bin" >> "$GITHUB_PATH" - name: Deploy env: LEAF_TOKEN: ${{ secrets.LEAF_TOKEN }} run: leaf app deploy web ${{ github.sha }} --waitThe job fails when the deploy does not succeed. See API keys for the scopes and Deploy from CI for the static-site version of this setup.