LOCALHOST
All pages
Tools

Deploying from Git

From a push to live, with no downtime.

Push to a branch and the site builds and goes live with no downtime. The new version starts beside the old one, traffic moves once it answers its health check, and the old one is retired. A build that fails leaves the live version serving.

From a push to live

  1. Your push reaches us through the GitHub App, or a webhook on the repository, or a call to POST /builds/ from your CI.
  2. We check out exactly one commit and read it before any of its code runs: a Dockerfile if there is one, otherwise the framework (Django, Flask, FastAPI, Laravel, PHP, Next.js, Node, static builds, plain files), plus the port, the services it needs and the settings it expects. lh.toml corrects anything detection gets wrong.
  3. The build runs under limits on the site's own server, with secrets kept out of the image, and the log is yours to follow: GET /builds/{id}?since=… returns the log from a character offset and the log_next to ask with next time. lh deploy does this for you.
  4. Health-checked rollout. The new version starts, we wait for it to answer, then move traffic. A release command (migrations, say) runs once first when the app has one. The commit gets a status on GitHub; the owner can be told on WhatsApp.

Connecting a repository

In the panel: Connect GitHub installs our GitHub App on your account or organisation, and the new-site page lists your repositories. Private repositories work. A pasted address works for GitLab and other hosts.

From the terminal: a new site from a repository, or connect an existing site.

lh create shop --repo you/shop --branch main
lh connect shop you/shop --tags 'v*'      # release only tags like v1.2.0
lh connect shop you/shop --previews       # a preview site per pull request

From code: POST /builds/sites makes the site and returns its first build; PUT /builds/sources/{slug} connects or changes the repository, branch, folder, Dockerfile path and trigger. See Git deploys in the reference.

What goes live. By default every push to the branch. With trigger: tag only tags matching the pattern go live and branch pushes build nothing; lh deploy shop --tag v1.2.0, the panel's Deploy tag, or a CI job posting {"site": "shop", "tag": "v1.2.0"} releases one by hand.

Webhooks for other hosts and CI

Every connected site has its own hook address, https://localhost.co.zw/hooks/git/<site id>/, with a secret shown on the site's page. GET /builds/sources/{slug} returns the address as webhook_url. It understands:

SenderHow it signsEvents
GitHub (without the App)X-Hub-Signature-256push, pull_request
GitLabX-Gitlab-Tokenpush, tag push, merge request
Gitea, ForgejoX-Gitea-Signaturepush
Your CI jobX-LH-Signature: sha256=<HMAC of the body with the secret>body {"branch": "main", "sha": "…"} or {"tag": "v1.2.0"}

Pushes to other branches, deleted branches, a commit already built, and commit messages carrying [skip deploy] or [skip ci] build nothing.

Pull-request previews

Turn previews on and each pull request from the same repository gets its own site at <site>-pr-<n>.sites.localhost.co.zw: built when it opens and on every push, removed when it closes or merges. It gets the main site's settings except the database address and anything lh.toml lists under previews.hide, plus PREVIEW=1, PREVIEW_PR and PREVIEW_BRANCH. Pull requests from forks never get one. With the GitHub App the preview shows as a commit status and one comment on the pull request. lh previews shop lists them; the API has GET /builds/previews?site=shop.

Rolling back

The last few live builds stay on the server, so going back is instant: lh rollback shop puts the previous live build back, --to 12 a particular one; the API has POST /builds/{id}/rollback. A rollback is a build of its own, with rollback_of set, so the history stays honest.

Settings during a build

A site's settings (lh env, /sites/{slug}/env) reach the app at run time. Mark one build and the build gets it too, for the NEXT_PUBLIC_* and VITE_* kind of thing; those are never secret. Mark one live-only and previews don't get it. Settings shared by every site live under /variables (lh env --all) and a site's own value wins over a shared one.