Add hosting deployment setup and backend health endpoint

This commit is contained in:
2026-03-18 19:00:19 +06:00
parent c839e16d60
commit e8e8ed6ba3
5 changed files with 118 additions and 1 deletions

33
HOSTING_DEPLOY.md Normal file
View File

@@ -0,0 +1,33 @@
# Hosting Deployment
## 1) Prerequisites
- Docker Engine + Docker Compose plugin
- Domain pointing to your host IP
- (Optional) HTTPS reverse proxy in front of port 80
## 2) Prepare environment
```bash
cp backend/.env.example backend/.env
cp deploy/.env.hosting.example deploy/.env
```
Edit `backend/.env`:
- `SECRET_KEY`
- `BASE_URL` and `FRONTEND_URL` (your real domain)
- `SSO_ENABLED=true` + `ZITADEL_*` only if you use SSO
## 3) Pull and run published images
```bash
docker compose --env-file deploy/.env -f deploy/docker-compose.hosting.yml pull
docker compose --env-file deploy/.env -f deploy/docker-compose.hosting.yml up -d
```
## 4) Verify
- Frontend: `http://<your-host>/`
- Backend health: `docker compose -f deploy/docker-compose.hosting.yml logs backend`
- Frontend health: `docker compose -f deploy/docker-compose.hosting.yml logs frontend`
## Notes
- Frontend uses same-origin `/api` in production, so no hardcoded API host is required.
- Backend health endpoint is `/health`.
- If you need local frontend->local backend development, use `frontend/.env.local`.

14
backend/.env.example Normal file
View File

@@ -0,0 +1,14 @@
# JWT
SECRET_KEY=change-me-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=43200
# OpenID Connect (SSO)
SSO_ENABLED=false
ZITADEL_ISSUER=
ZITADEL_CLIENT_ID=
ZITADEL_CLIENT_SECRET=
# URLs
BASE_URL=https://panel.example.com
FRONTEND_URL=https://panel.example.com

View File

@@ -172,6 +172,11 @@ def check_server_access(user: dict, server_name: str):
return False return False
return server_name in user.get("servers", []) return server_name in user.get("servers", [])
# Healthcheck endpoint for Docker/hosting probes
@app.get("/health")
async def health():
return {"status": "ok"}
# API для аутентификации # API для аутентификации
# OpenID Connect endpoints # OpenID Connect endpoints
@@ -1936,4 +1941,4 @@ app.include_router(daemons_router)
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) uvicorn.run(app, host="0.0.0.0", port=4546)

View File

@@ -0,0 +1,9 @@
# Image tag produced by Drone (latest or build number)
IMAGE_TAG=latest
# Optional explicit image names
# BACKEND_IMAGE=registry.nevetime.ru/mc-panel-backend:latest
# FRONTEND_IMAGE=registry.nevetime.ru/mc-panel-frontend:latest
# External port for the frontend container
FRONTEND_PORT=80

View File

@@ -0,0 +1,56 @@
version: '3.8'
services:
backend:
image: ${BACKEND_IMAGE:-registry.nevetime.ru/mc-panel-backend:${IMAGE_TAG:-latest}}
container_name: mc-panel-backend
restart: unless-stopped
env_file:
- ../backend/.env
environment:
PORT: 8000
WORKERS: 2
PYTHONPATH: /app
DEBUG: 'false'
volumes:
- mc_servers:/app/servers
- mc_data:/app/data
- mc_logs:/app/logs
networks:
- mc-panel-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
frontend:
image: ${FRONTEND_IMAGE:-registry.nevetime.ru/mc-panel-frontend:${IMAGE_TAG:-latest}}
container_name: mc-panel-frontend
restart: unless-stopped
ports:
- "${FRONTEND_PORT:-80}:80"
depends_on:
backend:
condition: service_healthy
networks:
- mc-panel-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
volumes:
mc_servers:
driver: local
mc_data:
driver: local
mc_logs:
driver: local
networks:
mc-panel-network:
driver: bridge