Files
anchorhost-backend/README.md
T
wfalkowski b8be6ad2fb
Build and publish Docker image / build-and-publish (push) Successful in 11s
fix: use CSI snapshots for server backups
2026-10-24 06:38:52 +00:00

99 lines
4.4 KiB
Markdown

<div align="center">
# AnchorHost Backend
**The API and control plane behind AnchorHost.**
[![Build and publish](https://git.anchorhost.eu/anchorhost.eu/anchorhost-backend/actions/workflows/docker.yml/badge.svg?branch=main)](https://git.anchorhost.eu/anchorhost.eu/anchorhost-backend/actions)
![Python 3.12](https://img.shields.io/badge/python-3.12-3776AB?logo=python&logoColor=white)
![Flask](https://img.shields.io/badge/API-Flask-000000?logo=flask&logoColor=white)
![License: MIT](https://img.shields.io/badge/license-MIT-2F6F5E.svg)
</div>
---
AnchorHost Backend serves the platform's HTTP API and WebSocket connection for account, billing, domain, server, and support operations. It integrates with PostgreSQL, Kubernetes, Stripe, OAuth providers, SMTP, and deSEC.
## Start locally
Requires Python 3.12 and access to a PostgreSQL database for a production-like run. SQLite remains available for isolated local development.
```bash
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
```
Set `DATABASE_URL` and a persistent `JWT_SECRET` in `.env`, then start the API and WebSocket service together:
```bash
python app.py
```
The HTTP API listens on `http://localhost:8080` and the WebSocket service listens on port `8081` by default. The health endpoint is `GET /health`.
## Build and publish
Pushes to `main` build the container and publish these tags to the Gitea Container Registry:
```text
git.anchorhost.eu/anchorhost.eu/anchorhost-backend:backend
git.anchorhost.eu/anchorhost.eu/anchorhost-backend:main-<commit>
```
The workflow needs a repository secret named `REGISTRY_TOKEN` with package read and write access. Run it manually from **Actions → Build and publish Docker image** when needed.
Build the image locally with:
```bash
docker build -t anchorhost-backend:local .
```
## Longhorn backups
Server backups use Kubernetes CSI `VolumeSnapshot` resources. The cluster must have the matching snapshot CRDs and controller installed, plus the `longhorn-snapshot` `VolumeSnapshotClass` in [`k8s/longhorn-snapshot-class.yaml`](k8s/longhorn-snapshot-class.yaml). Keep the external-snapshotter CRD/controller release aligned with the CSI snapshotter sidecar bundled with Longhorn. For the current Longhorn 1.9.0 setup, that version is v8.2.0.
On a cluster that does not provide the snapshot CRDs, install the CRDs from the pinned external-snapshotter release and apply the class:
```bash
kubectl apply -k 'https://github.com/kubernetes-csi/external-snapshotter/client/config/crd?ref=v8.2.0'
kubectl apply -k 'https://github.com/kubernetes-csi/external-snapshotter/deploy/kubernetes/snapshot-controller?ref=v8.2.0'
kubectl apply -f k8s/longhorn-snapshot-class.yaml
```
The snapshot controller must also be running. Before upgrading Longhorn or the snapshotter, check the matching CRD/controller version in the Longhorn release documentation. A backup is only marked **Completed** after the CSI snapshot reports `readyToUse`; restores verify the snapshot and wait for Longhorn to finish restoring the volume before starting the server.
## Configuration
| Variable | Purpose |
| --- | --- |
| `DATABASE_URL` | PostgreSQL URL in production; SQLite URL or file path for local development. |
| `JWT_SECRET` | Persistent random secret of at least 32 characters. |
| `PORT`, `WS_PORT` | HTTP and WebSocket listen ports; defaults are `8080` and `8081`. |
| `STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET` | Stripe checkout and webhook integration. |
| `GOOGLE_*`, `APPLE_*` | OAuth client and callback configuration. |
| `DESEC_API_TOKEN`, `BASE_DOMAIN` | DNS and domain management. |
| `SMTP_*`, `BASE_URL`, `FRONTEND_URL` | Transactional email settings and links. |
| `KUBECONFIG` | Optional local kubeconfig path; in-cluster credentials are used in Kubernetes. |
Copy `.env.example` as a starting point. Keep production values in deployment secrets; do not commit `.env` or credentials.
## Project structure
```text
app.py Application entry point
application.py Flask application factory
routes/ HTTP endpoints grouped by feature
database_service.py Schema initialization and database operations
*_service.py Feature services and integrations
server_*.py Server lifecycle, access, capacity, and billing
websocket_service.py WebSocket server and client sessions
main.py Background workers and process startup
```
## License
MIT © 2026 Wiktor A. Falkowski. See [LICENSE](LICENSE).