172 lines
3.0 KiB
Markdown
172 lines
3.0 KiB
Markdown
# UI Service - Docker
|
|
|
|
FastAPI + Jinja2 + HTMX Dashboard für Home Automation
|
|
|
|
## Build
|
|
|
|
```bash
|
|
docker build -t ui:dev -f apps/ui/Dockerfile .
|
|
```
|
|
|
|
## Run
|
|
|
|
### Lokal
|
|
```bash
|
|
docker run --rm -p 8002:8002 -e API_BASE=http://localhost:8001 ui:dev
|
|
```
|
|
|
|
### Docker Compose
|
|
```yaml
|
|
services:
|
|
ui:
|
|
build:
|
|
context: .
|
|
dockerfile: apps/ui/Dockerfile
|
|
ports:
|
|
- "8002:8002"
|
|
environment:
|
|
- API_BASE=http://api:8001
|
|
depends_on:
|
|
- api
|
|
```
|
|
|
|
### Kubernetes
|
|
```yaml
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: ui
|
|
spec:
|
|
replicas: 2
|
|
selector:
|
|
matchLabels:
|
|
app: ui
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: ui
|
|
spec:
|
|
containers:
|
|
- name: ui
|
|
image: ui:dev
|
|
ports:
|
|
- containerPort: 8002
|
|
env:
|
|
- name: API_BASE
|
|
value: "http://api-service:8001"
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /health
|
|
port: 8002
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 10
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /health
|
|
port: 8002
|
|
initialDelaySeconds: 3
|
|
periodSeconds: 5
|
|
resources:
|
|
requests:
|
|
memory: "128Mi"
|
|
cpu: "100m"
|
|
limits:
|
|
memory: "256Mi"
|
|
cpu: "500m"
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: ui-service
|
|
spec:
|
|
selector:
|
|
app: ui
|
|
ports:
|
|
- protocol: TCP
|
|
port: 8002
|
|
targetPort: 8002
|
|
type: LoadBalancer
|
|
```
|
|
|
|
## Umgebungsvariablen
|
|
|
|
| Variable | Default | Beschreibung |
|
|
|----------|---------|--------------|
|
|
| `API_BASE` | `http://api:8001` | URL des API-Services |
|
|
| `UI_PORT` | `8002` | Port der UI-Anwendung |
|
|
| `PYTHONDONTWRITEBYTECODE` | `1` | Keine .pyc Files |
|
|
| `PYTHONUNBUFFERED` | `1` | Unbuffered Output |
|
|
|
|
## Endpoints
|
|
|
|
- `GET /` - Dashboard
|
|
- `GET /health` - Health Check
|
|
- `GET /dashboard` - Dashboard (alias)
|
|
|
|
## Security
|
|
|
|
- Container läuft als **non-root** User `app` (UID: 10001)
|
|
- Minimales Python 3.11-slim Base Image
|
|
- Keine unnötigen System-Pakete
|
|
- Health Check integriert
|
|
|
|
## Features
|
|
|
|
- ✅ FastAPI Backend
|
|
- ✅ Jinja2 Templates
|
|
- ✅ HTMX für reactive UI
|
|
- ✅ Server-Sent Events (SSE)
|
|
- ✅ Responsive Design
|
|
- ✅ Docker & Kubernetes ready
|
|
- ✅ Health Check Endpoint
|
|
- ✅ Non-root Container
|
|
- ✅ Configurable API Backend
|
|
|
|
## Entwicklung
|
|
|
|
### Lokales Testing
|
|
```bash
|
|
# Build
|
|
docker build -t ui:dev -f apps/ui/Dockerfile .
|
|
|
|
# Run
|
|
docker run -d --name ui-test -p 8002:8002 -e API_BASE=http://localhost:8001 ui:dev
|
|
|
|
# Logs
|
|
docker logs -f ui-test
|
|
|
|
# Health Check
|
|
curl http://localhost:8002/health
|
|
|
|
# Cleanup
|
|
docker stop ui-test && docker rm ui-test
|
|
```
|
|
|
|
### Tests
|
|
```bash
|
|
bash /tmp/test_ui_dockerfile.sh
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Container startet nicht
|
|
```bash
|
|
docker logs ui-test
|
|
```
|
|
|
|
### Health Check schlägt fehl
|
|
```bash
|
|
docker exec ui-test curl http://localhost:8002/health
|
|
```
|
|
|
|
### API_BASE nicht korrekt
|
|
```bash
|
|
docker logs ui-test 2>&1 | grep "UI using API_BASE"
|
|
```
|
|
|
|
### Non-root Verifizieren
|
|
```bash
|
|
docker exec ui-test id
|
|
# Sollte zeigen: uid=10001(app) gid=10001(app)
|
|
```
|