# One-Click Deploy Templates

Community templates for deploying chmonitor on Railway, Render, and Fly.io.

> **Honest note:** These are starting-point templates, not verified CI pipelines. They have not been boot-tested end-to-end against a live ClickHouse instance in automated CI. Review the env var placeholders, substitute real values, and verify the deployment works in your environment before relying on it in production.

All three templates run the published image `ghcr.io/duyet/chmonitor:latest`, expose port 3000, and define a health check against `/api/healthz`. You must supply three env vars:

| Variable | Description |
|---|---|
| `CLICKHOUSE_HOST` | ClickHouse HTTP URL, e.g. `http://your-host:8123` |
| `CLICKHOUSE_USER` | ClickHouse username |
| `CLICKHOUSE_PASSWORD` | ClickHouse password (use your platform's secret store) |

The template files live in [`deploy/templates/`](https://github.com/duyet/clickhouse-monitoring/tree/main/deploy/templates) in the repository.

---

## Railway

Template: [`deploy/templates/railway.json`](https://github.com/duyet/clickhouse-monitoring/blob/main/deploy/templates/railway.json)

1. In the Railway dashboard, choose **New Project → Deploy from image**.
2. Set the image to `ghcr.io/duyet/chmonitor:latest`.
3. Add the three env vars above (Railway → Variables tab). Use Railway's secret management for `CLICKHOUSE_PASSWORD`.
4. Railway auto-assigns a public URL. The health check path is `/api/healthz`.

Alternatively, copy `deploy/templates/railway.json` into your repository root as `railway.json` — Railway picks it up automatically on the next deploy.

```json
{
  "build": {
    "builder": "IMAGE",
    "image": "ghcr.io/duyet/chmonitor:latest"
  },
  "deploy": {
    "healthcheckPath": "/api/healthz"
  }
}
```

---

## Render

Template: [`deploy/templates/render.yaml`](https://github.com/duyet/clickhouse-monitoring/blob/main/deploy/templates/render.yaml)

1. Fork or copy `deploy/templates/render.yaml` as `render.yaml` in your repository root.
2. In the Render dashboard, choose **New → Blueprint** and point it at your repository.
3. Render reads `render.yaml`, pulls `ghcr.io/duyet/chmonitor:latest`, and creates the service.
4. Set `CLICKHOUSE_PASSWORD` as a **Secret** in the Render environment (do not store it in plain text in `render.yaml`).

Key snippet:

```yaml
services:
  - type: web
    name: chmonitor
    image: ghcr.io/duyet/chmonitor:latest
    healthCheckPath: /api/healthz
    envVars:
      - key: CLICKHOUSE_HOST
        value: http://YOUR_CLICKHOUSE_HOST:8123
      - key: CLICKHOUSE_USER
        value: YOUR_CLICKHOUSE_USER
      - key: CLICKHOUSE_PASSWORD
        value: YOUR_CLICKHOUSE_PASSWORD   # use Render secret instead
```

---

## Fly.io

Template: [`deploy/templates/fly.toml`](https://github.com/duyet/clickhouse-monitoring/blob/main/deploy/templates/fly.toml)

1. Install the [Fly CLI](https://fly.io/docs/hands-on/install-flyctl/) and run `fly auth login`.
2. Copy `deploy/templates/fly.toml` to your working directory.
3. Edit `app`, `primary_region`, and `CLICKHOUSE_HOST` / `CLICKHOUSE_USER`.
4. Store the password as a secret (not in `fly.toml`):

```bash
fly secrets set CLICKHOUSE_PASSWORD=your-password
```

5. Deploy:

```bash
fly launch --no-deploy   # imports fly.toml
fly deploy
```

The health check polls `/api/healthz` every 10 seconds with a 20-second grace period on startup.

---

## After deploying

- Open `https://your-app-url` — you should land on the overview page.
- If the page loads but charts are empty, check that the ClickHouse user has `SELECT` on `system.*`.
- If the health check fails, verify `CLICKHOUSE_HOST` is reachable from inside the container (use the private/internal hostname your platform provides, not `localhost`).
- For additional configuration (authentication, AI agent, conversation store), see the [Docker deploy guide](/deploy/docker) — the same env vars apply.
