Phase 8: widgets and polish
- Live job card widget (progress bar, in-widget cancel via widget_query) and live invoice widget (QR drawn from a bitmap, countdown, paid state), Bot API 10.4 sendWidget, private chats only - Automatic fallback to the ordinary message when sendWidget fails, with a breaker that pauses widgets after repeated failures or on servers without the method; TELEGRAM_WIDGETS - Prometheus metrics on the core (/metrics) and on every worker: queue depth and wait, slots, heartbeats, job outcomes, errors per site, deliveries, cache, invoices, Lightning, ledger check, widgets - Example Prometheus config and alert rules, Caddyfile, dashboard notes - Load test: cmd/loadtest and deploy/loadtest (make loadtest) - Browser check of the widgets' HTML, including decoding a drawn QR - docs/DEPLOY.md (production in under an hour) and docs/MONITORING.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f1f9c6156c
commit
3c153af97f
+176
@@ -0,0 +1,176 @@
|
||||
# Deploying in under an hour
|
||||
|
||||
One path from nothing to a running bot with two download workers,
|
||||
payments, the Mini App and monitoring. Each step says how long it takes
|
||||
and how to check it worked. Later steps are optional; the bot works after
|
||||
step 4.
|
||||
|
||||
The other documents go deeper: [OPERATIONS.md](OPERATIONS.md) (choices,
|
||||
backups, updates), [WORKERS.md](WORKERS.md), [MONITORING.md](MONITORING.md).
|
||||
|
||||
## 0. What you need (5 minutes to gather)
|
||||
|
||||
- A Linux server with a public IP address: 2 CPU cores, 2 GB of memory and
|
||||
20 GB of disk are plenty to start. Debian or Ubuntu are assumed below.
|
||||
- A domain or subdomain pointing at it, for example `bot.example.com`
|
||||
(an A record). Payments work without one, the Mini App does not.
|
||||
- A Telegram account, and its numeric user ID (send any message to
|
||||
@userinfobot, or leave `OWNER_IDS` empty for now and fill it in later).
|
||||
- For payments: an LNbits wallet and its **invoice/read key** (not the admin
|
||||
key). LNbits 0.12 or newer.
|
||||
|
||||
## 1. Create the bot (5 minutes)
|
||||
|
||||
In Telegram, talk to @BotFather:
|
||||
|
||||
1. `/newbot`, pick a name and a username. Copy the token.
|
||||
2. Leave group privacy on. The bot only needs commands in groups, unless
|
||||
a group wants pasted links fetched (see `/autodetect`).
|
||||
|
||||
The bot sets its own description, short description and command menus in
|
||||
English, Spanish and Dutch when it starts.
|
||||
|
||||
## 2. Prepare the server (10 minutes)
|
||||
|
||||
```sh
|
||||
# Docker with the compose plugin
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
|
||||
git clone <this repository> /opt/dlbot && cd /opt/dlbot
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Edit `.env`. This is enough for a first start:
|
||||
|
||||
```sh
|
||||
BOT_TOKEN=123456789:AA... # from step 1
|
||||
OWNER_IDS=111111111 # your Telegram user ID
|
||||
WORKER_A_TOKEN=<openssl rand -hex 24>
|
||||
WORKER_B_TOKEN=<openssl rand -hex 24>
|
||||
```
|
||||
|
||||
Every other setting has a working default. `.env.example` explains each
|
||||
of them; the limits and prices are near the top.
|
||||
|
||||
## 3. Start it (10 minutes, mostly the first build)
|
||||
|
||||
```sh
|
||||
docker compose up -d --build
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
All three services (`core`, `worker-a`, `worker-b`) should turn
|
||||
`healthy` within a minute after the build.
|
||||
|
||||
```sh
|
||||
curl -s localhost:8080/healthz # {"status":"ok"}
|
||||
```
|
||||
|
||||
## 4. Check it in Telegram (5 minutes)
|
||||
|
||||
1. Open your bot, press Start. The welcome text appears.
|
||||
2. Send a link to a video (any public video page). A card with formats
|
||||
appears; pick one, and the file arrives.
|
||||
3. Send `/workers`: both workers are listed as active.
|
||||
4. Send `/stats`: users, the queue, "Books: ledger and balances agree".
|
||||
|
||||
If nothing answers: `docker compose logs core | tail -50`. A wrong token
|
||||
shows as an error at startup.
|
||||
|
||||
From here the bot is in service, with the free tier only.
|
||||
|
||||
## 5. TLS and the public address (10 minutes)
|
||||
|
||||
Needed for instant payment confirmation, the Mini App and workers on other
|
||||
machines.
|
||||
|
||||
```sh
|
||||
sudo apt install -y caddy
|
||||
sudo cp deploy/caddy/Caddyfile /etc/caddy/Caddyfile
|
||||
sudo sed -i 's/bot.example.com/<your domain>/' /etc/caddy/Caddyfile
|
||||
sudo systemctl reload caddy
|
||||
curl -s https://<your domain>/healthz # {"status":"ok"}, with a valid certificate
|
||||
```
|
||||
|
||||
Add to `.env`:
|
||||
|
||||
```sh
|
||||
PUBLIC_URL=https://<your domain>
|
||||
```
|
||||
|
||||
## 6. Payments (10 minutes)
|
||||
|
||||
Add to `.env`:
|
||||
|
||||
```sh
|
||||
LNBITS_URL=https://<your lnbits>
|
||||
LNBITS_INVOICE_KEY=<invoice/read key>
|
||||
LNBITS_WEBHOOK_SECRET=<openssl rand -hex 16>
|
||||
```
|
||||
|
||||
Then `docker compose up -d` (it restarts the core with the new settings).
|
||||
|
||||
Check: send `/buy`, pick the day pass, pay the invoice from any Lightning
|
||||
wallet. Within seconds the invoice turns into "Paid" and `/account` shows
|
||||
the pass. `/stats` shows "Lightning: reachable". Prices are in `.env`
|
||||
(`PRICE_*`).
|
||||
|
||||
## 7. The Mini App (5 minutes)
|
||||
|
||||
Add `MINIAPP_ENABLED=true` to `.env` and `docker compose up -d`. In
|
||||
@BotFather: `/mybots`, your bot, **Bot Settings**, **Configure Mini App**,
|
||||
**Enable Mini App**, URL `https://<your domain>/app/`.
|
||||
|
||||
Check: send `/app` and press the button. The app opens on the Home tab.
|
||||
|
||||
## 8. Monitoring (10 minutes)
|
||||
|
||||
Point a Prometheus at the core's `/metrics`. On the same machine, as a
|
||||
container on the compose network:
|
||||
|
||||
```sh
|
||||
mkdir -p /opt/prometheus
|
||||
cp deploy/prometheus/prometheus.yml deploy/prometheus/alerts.yml /opt/prometheus/
|
||||
docker run -d --name prometheus --restart unless-stopped --network dlbot_default \
|
||||
-v /opt/prometheus:/etc/prometheus -p 127.0.0.1:9090:9090 prom/prometheus
|
||||
```
|
||||
|
||||
Check: `http://localhost:9090/targets` (through an SSH tunnel) shows the
|
||||
core and both workers up. [MONITORING.md](MONITORING.md) lists the
|
||||
metrics, dashboard panels and what the alerts mean.
|
||||
|
||||
## 9. More workers, elsewhere (10 minutes each, optional)
|
||||
|
||||
On the core: `docker compose exec core core worker add home-1` prints a
|
||||
token. On the other machine, with Docker:
|
||||
|
||||
```sh
|
||||
docker build -f deploy/Dockerfile --target worker -t dlbot-worker .
|
||||
docker run -d --name dlbot-worker --restart unless-stopped \
|
||||
-e CORE_URL=https://<your domain> -e WORKER_TOKEN=<token> \
|
||||
-e WORKER_TAGS=residential dlbot-worker
|
||||
```
|
||||
|
||||
`/workers` lists it within seconds. Sites that refuse datacenter
|
||||
addresses can be routed to it with `SITE_TAGS`, see
|
||||
[WORKERS.md](WORKERS.md).
|
||||
|
||||
## After the first hour
|
||||
|
||||
- **Backups:** the `core-data` volume holds the SQLite database and the
|
||||
cached files; only the database matters. See [OPERATIONS.md](OPERATIONS.md#backups).
|
||||
- **Updates:** `git pull && docker compose up -d --build`. Migrations run
|
||||
at startup. yt-dlp updates itself on every worker daily, or now with
|
||||
`/ytdlp update`.
|
||||
- **Texts:** `/privacy`, `/terms` and `/support` are short templates in
|
||||
`locales/*.toml`. Make them yours before going public.
|
||||
- **Limits and prices:** `.env`, `FREE_*`, `PAID_*` and `PRICE_*`.
|
||||
|
||||
## What was and was not tried
|
||||
|
||||
Steps 2 to 4 and 6 to 7 are the same commands the automated tests and the
|
||||
acceptance scripts run, with processes instead of containers: the Docker
|
||||
images and the compose file were checked with `docker compose config` but
|
||||
not built or started on the machine this was written on, which had no
|
||||
Docker access. The Caddy and Prometheus snippets follow their
|
||||
documentation and were not run either.
|
||||
Reference in New Issue
Block a user