- Remove all hardcoded credentials and config from Python source code:
- db.py: DB host/user/password/name/port → env vars with connection retry support
- cm_bot_hal.py: prefix, agent_id, agent_password, security_pin → env vars
- cm_bot.py: base_url → env var, fix register_user return values
- cm_web_view.py: hardcoded '13c' prefix → configurable CM_PREFIX_PATTERN
- cm_telegram.py: hardcoded 'Sky533535' pin → env var CM_SECURITY_PIN
- Parameterize docker-compose.yml for multi-deployment on same host:
- Container names use ${CM_DEPLOY_NAME} prefix (e.g. rex-cm-*, siong-cm-*)
- Network name uses ${CM_DEPLOY_NAME}-network
- Web view port configurable via ${CM_WEB_HOST_PORT}
- All service config passed as env vars (not baked into image)
- Add per-deployment env configs:
- envs/rex/.env (port 8001, prefix 13c, DB rex_cm)
- envs/siong/.env (port 8005, prefix 13sa, DB siong_cm)
- .env.example as template for new deployments
- Remove .env from .gitignore (local server, safe to commit)
- Improve telegram bot reliability:
- Add retry logic for polling with exponential backoff
- Add error handlers for Conflict, RetryAfter, NetworkError, TimedOut
- Add /9 command to show chat ID
- Add telegram_notifier.py for alert notifications
- Fix error handling in /2 and /3 command handlers
- Fix db.py cursor cleanup (close cursor before connection in finally blocks)
- Fix docker-compose.override.yml environment syntax (list → mapping)
- Update README with multi-deployment instructions
- Add AGENTS.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.6 KiB
Markdown
64 lines
2.6 KiB
Markdown
# CM Bot v2 – Portainer Setup (Gitea Registry)
|
||
|
||
Brief, copy/paste-ready steps to run the published images from `gitea.04080616.xyz` using Portainer.
|
||
|
||
## What gets deployed
|
||
- `cm-api` (port 3000), `cm-web` (port 8000 → host `CM_WEB_HOST_PORT`), `cm-telegram`, `cm-transfer`
|
||
- Container names prefixed with `CM_DEPLOY_NAME` (e.g. `rex-cm-telegram-bot`)
|
||
- Docker network: `${CM_DEPLOY_NAME}-network` (bridge)
|
||
|
||
## Environment configs
|
||
|
||
Pre-configured `.env` files for each deployment are in the `envs/` folder:
|
||
```
|
||
envs/
|
||
├── rex/.env # Rex deployment (port 8001)
|
||
└── siong/.env # Siong deployment (port 8005)
|
||
```
|
||
|
||
For local development, copy the desired env to the project root:
|
||
```bash
|
||
cp envs/rex/.env .env
|
||
# or
|
||
cp envs/siong/.env .env
|
||
```
|
||
|
||
For Portainer, load the env vars from the appropriate file into the stack environment variables.
|
||
|
||
## Key variables
|
||
| Variable | Description |
|
||
|---|---|
|
||
| `CM_DEPLOY_NAME` | Unique prefix for containers/network (e.g. `rex-cm`, `siong-cm`) |
|
||
| `CM_WEB_HOST_PORT` | Host port for web view (must be unique per deployment) |
|
||
| `TELEGRAM_BOT_TOKEN` | Your Telegram bot token |
|
||
| `DB_HOST` / `DB_USER` / `DB_PASSWORD` / `DB_NAME` | Database connection |
|
||
| `CM_PREFIX_PATTERN` | Username prefix pattern |
|
||
| `CM_AGENT_ID` / `CM_AGENT_PASSWORD` / `CM_SECURITY_PIN` | Agent credentials |
|
||
| `CM_BOT_BASE_URL` | Bot API base URL |
|
||
|
||
## One-time: add the registry in Portainer
|
||
1) Portainer → **Registries** → **Add registry** → **Custom**.
|
||
2) Name: `gitea-prod` (any)
|
||
3) Registry URL: `gitea.04080616.xyz`
|
||
4) Username: your Gitea username; Password: the PAT. Save.
|
||
|
||
## Deploy the stack (fast path)
|
||
1) Portainer → **Stacks** → **Add stack** → **Web editor**.
|
||
2) Paste the contents of `docker-compose.yml` from this repo (not the override).
|
||
3) Load all variables from the appropriate `envs/<name>/.env` into the stack environment variables.
|
||
4) Click **Deploy the stack**. Portainer will pull `cm-<service>:<tag>` from `gitea.04080616.xyz/yiekheng` and start all four containers.
|
||
|
||
## Updating to a new image tag
|
||
1) Edit the stack → change `DOCKER_IMAGE_TAG` → **Update the stack**.
|
||
2) Portainer re-pulls and recreates the services with the new tag.
|
||
|
||
## Running multiple deployments on same host
|
||
Each deployment needs unique values for:
|
||
- `CM_DEPLOY_NAME` – avoids container/network name conflicts
|
||
- `CM_WEB_HOST_PORT` – avoids port conflicts
|
||
|
||
## Common issues
|
||
- **Pull denied**: PAT missing `read:package` or wrong username/PAT in the registry entry.
|
||
- **Port already allocated**: check `CM_WEB_HOST_PORT` is unique across deployments.
|
||
- **No port bindings applied**: ensure network driver stays `bridge` (not `host` or `macvlan`).
|