> ## Documentation Index
> Fetch the complete documentation index at: https://aeros-c1d071c8.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy and rollback

> Pull from Git, install dependencies only when lockfiles change, build, restart, and roll back to the previous commit.

Deploys run inside the panel process. There is no CI runner or build agent. Every line of output goes to the project terminal over the WebSocket that is already streaming the service's journal.

![Deploy output streamed to the terminal](https://mintcdn.com/aeros-c1d071c8/8fuJs39e8BgaLs5j/projects-terminal.png?fit=max\&auto=format\&n=8fuJs39e8BgaLs5j\&q=85\&s=449ed77053e58f8264d72749da291486)

Deploy output in the project terminal.

## Deploy

Select a project and press **DEPLOY**. The panel answers `202 Accepted` right away and runs the pipeline in the background. Only one deploy or rollback can run per service at a time. A second request gets `409`.

**1. Validate**

Checks the service name, working directory, and branch with the same guards used at creation (`assertManageableServiceName`, `validateWorkDir`, `validateGitBranch`).

**2. Clone or pull**

* **No `.git` in the working directory and a repository is set:** `git clone --branch <branch> -- <repository> <work_dir>`. The repository URL is checked again with `validateRepositoryUrl`.
* **Existing checkout:** `git fetch --prune origin -- <branch>`, then `git pull --ff-only origin -- <branch>`. A diverged checkout fails instead of merging.
* **No `.git` and no repository:** Git is skipped and the existing directory is used as is.

**3. Install dependencies when needed**

Before pulling, the panel hashes `package.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `requirements.txt`, and `pyproject.toml` with SHA-256. After pulling, it hashes them again.

**Node:** installs when `node_modules` is missing, when any Node lockfile or `package.json` changed, or after a fresh clone. It uses `pnpm install --frozen-lockfile`, `yarn install --frozen-lockfile`, `npm ci`, or `npm install`, depending on which lockfile exists.

**Python:** when `requirements.txt` changed, runs `pip install -r requirements.txt` with `.venv/bin/pip` if it exists, or `pip3` otherwise.

If nothing changed, the terminal prints `Lockfile unchanged. Skipping Node dependency install.`

**4. Build**

Runs the project's build command through a shell if one is set. Otherwise, for the Node.js and Static templates, runs `npm run build` when `package.json` has a `build` script.

**5. Restart**

Runs `systemctl restart <service>` and stores the new commit in SQLite.

The terminal ends with `[DEPLOY] Completed in 12.3s. Service restarted.` or `[DEPLOY] FAILED: <reason>`.

Deploy output is sent only to open terminals for that service. It is not stored or written to the journal, so a deploy that runs while no terminal is open (for example from a webhook) leaves no log. `last_deploy_at` and `current_commit` change only when it succeeds.

> [!NOTE]
>
> Commands run with `CI=true` in the environment. The configured build command is shown as `configured build command` in the terminal instead of its full text, so secrets passed on the command line are not echoed.

## Commit history

Each project stores two commit SHAs in the `projects` table:

| Column | Meaning |
| :- | :- |
| `current_commit` | The commit that was last deployed or rolled back to successfully. |
| `previous_commit` | The deployed commit before that one. This is the rollback target. |
| `last_deploy_at` | ISO timestamp of the last successful deploy or rollback. |

A deploy that does not change `HEAD` keeps the existing `previous_commit`. A failed deploy does not touch these columns.

## Rollback

**ROLLBACK** is enabled when `previous_commit` is set. After you confirm, the panel:

**1. Checks the target**

Confirms the request's `commit` still equals the stored `previous_commit` (otherwise `409`), and that the SHA resolves to a commit in the local checkout.

**2. Resets the checkout**

Runs `git reset --hard <previous_commit>`. Local changes to tracked files are discarded.

**3. Reinstalls and rebuilds**

Applies the same lockfile comparison and build step as a deploy.

**4. Restarts and records**

Restarts the service. `current_commit` becomes the rollback target and `previous_commit` becomes the commit you rolled back from, so you can roll forward again.

If any step fails, the panel resets the checkout to where it was, rebuilds, and restarts the service again if it already restarted it. Then it reports `[ROLLBACK] FAILED: <reason>`.

> [!WARNING]
>
> Rollback uses the local Git history. It can only return to the one commit stored in `previous_commit`. It does not roll back databases, `.env` files, or other state your app writes.

## GitHub webhooks

A push to the project branch can trigger the same deploy pipeline. GitHub calls the panel, so no polling is involved.

**1. Generate a secret**

In the project toolbar, open **Configure GitHub Push Webhook** and generate a secret. The panel shows the payload URL and the secret. The secret is shown once and is never returned by `GET /api/projects`. Generating again replaces it.

**2. Add the webhook on GitHub**

In the repository, go to **Settings > Webhooks > Add webhook**:

* **Payload URL:** `https://<your-panel-host>/api/webhooks/github/<project-id>`
* **Content type:** `application/json`
* **Secret:** the secret from the panel
* **Events:** Just the push event

**3. Check the ping**

GitHub sends a `ping` event. The panel answers `200` with `{"ok": true, "event": "ping"}` when the signature is valid.

GitHub must be able to reach the panel. Use a public domain through [Caddy](https://aeros-c1d071c8.mintlify.site/domains-and-remote-access.md#caddy-domains-and-https) or a [Cloudflare Tunnel](https://aeros-c1d071c8.mintlify.site/domains-and-remote-access.md#cloudflare-tunnel). Tailscale-only hosts cannot receive GitHub webhooks.

The request format, signature check, and responses are in the [webhook API reference](https://aeros-c1d071c8.mintlify.site/api/webhooks.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.