Compare commits
28 Commits
coolify
...
65177d3ff7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65177d3ff7 | ||
|
|
559d6a351c | ||
|
|
8fd11998e4 | ||
|
|
4ce649aa71 | ||
|
|
5ee3cc0104 | ||
|
|
b36712247b | ||
|
|
86b11c7e5f | ||
|
|
8003dcac39 | ||
|
|
778c44226e | ||
|
|
79891063dd | ||
|
|
2c9b0dc448 | ||
|
|
3133615044 | ||
|
|
2bc0f87325 | ||
|
|
4ee38d6f0b | ||
|
|
992d4f2a6b | ||
|
|
8f5f9641c7 | ||
|
|
7cdb53051f | ||
|
|
d834753a98 | ||
|
|
395011d0f4 | ||
|
|
9e1660f954 | ||
|
|
13ff930b5e | ||
|
|
5d1c837f49 | ||
|
|
1dd9662037 | ||
|
|
4626edb232 | ||
|
|
3c29b621ac | ||
|
|
755570d474 | ||
|
|
e890b1490a | ||
|
|
d15de16c47 |
@@ -140,20 +140,117 @@ jobs:
|
|||||||
python -m pytest tests/bqas/ -v --tb=short || true
|
python -m pytest tests/bqas/ -v --tb=short || true
|
||||||
|
|
||||||
# ========================================
|
# ========================================
|
||||||
# Deploy via Coolify (nur main, kein PR)
|
# Build & Deploy auf Hetzner (nur main, kein PR)
|
||||||
# ========================================
|
# ========================================
|
||||||
|
|
||||||
deploy-coolify:
|
deploy-hetzner:
|
||||||
name: Deploy
|
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
needs:
|
needs:
|
||||||
- test-go-consent
|
- test-go-consent
|
||||||
container:
|
container: docker:27-cli
|
||||||
image: alpine:latest
|
|
||||||
steps:
|
steps:
|
||||||
- name: Trigger Coolify deploy
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache curl
|
set -euo pipefail
|
||||||
curl -sf "${{ secrets.COOLIFY_WEBHOOK }}" \
|
DEPLOY_DIR="/opt/breakpilot-core"
|
||||||
-H "Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}"
|
COMPOSE_FILES="-f docker-compose.yml -f docker-compose.hetzner.yml"
|
||||||
|
COMMIT_SHA="${GITHUB_SHA:-unknown}"
|
||||||
|
SHORT_SHA="${COMMIT_SHA:0:8}"
|
||||||
|
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
|
|
||||||
|
# Services die deployed werden
|
||||||
|
SERVICES="postgres valkey qdrant minio ollama mailpit embedding-service rag-service backend-core consent-service health-aggregator"
|
||||||
|
|
||||||
|
echo "=== BreakPilot Core Deploy ==="
|
||||||
|
echo "Commit: ${SHORT_SHA}"
|
||||||
|
echo "Deploy Dir: ${DEPLOY_DIR}"
|
||||||
|
echo "Services: ${SERVICES}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 1. Repo auf dem Host erstellen/aktualisieren via Helper-Container
|
||||||
|
echo "=== Updating code on host ==="
|
||||||
|
docker run --rm \
|
||||||
|
-v "${DEPLOY_DIR}:${DEPLOY_DIR}" \
|
||||||
|
--entrypoint sh \
|
||||||
|
alpine/git:latest \
|
||||||
|
-c "
|
||||||
|
if [ ! -d '${DEPLOY_DIR}/.git' ]; then
|
||||||
|
echo 'Erstmaliges Klonen nach ${DEPLOY_DIR}...'
|
||||||
|
git clone '${REPO_URL}' '${DEPLOY_DIR}'
|
||||||
|
else
|
||||||
|
cd '${DEPLOY_DIR}'
|
||||||
|
git fetch origin main
|
||||||
|
git reset --hard origin/main
|
||||||
|
fi
|
||||||
|
"
|
||||||
|
echo "Code aktualisiert auf ${SHORT_SHA}"
|
||||||
|
|
||||||
|
# 2. .env sicherstellen
|
||||||
|
docker run --rm -v "${DEPLOY_DIR}:${DEPLOY_DIR}" alpine \
|
||||||
|
sh -c "
|
||||||
|
if [ ! -f '${DEPLOY_DIR}/.env' ]; then
|
||||||
|
echo 'WARNUNG: ${DEPLOY_DIR}/.env fehlt!'
|
||||||
|
echo 'Erstelle .env aus .env.example mit Defaults...'
|
||||||
|
if [ -f '${DEPLOY_DIR}/.env.example' ]; then
|
||||||
|
cp '${DEPLOY_DIR}/.env.example' '${DEPLOY_DIR}/.env'
|
||||||
|
echo '.env aus .env.example erstellt'
|
||||||
|
else
|
||||||
|
echo 'Kein .env.example gefunden — Services starten mit Defaults'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo '.env vorhanden'
|
||||||
|
fi
|
||||||
|
"
|
||||||
|
|
||||||
|
# 3. Shared Network erstellen (falls noch nicht vorhanden)
|
||||||
|
docker network create breakpilot-network 2>/dev/null || true
|
||||||
|
|
||||||
|
# 4. Build + Deploy via Helper-Container
|
||||||
|
echo ""
|
||||||
|
echo "=== Building + Deploying ==="
|
||||||
|
docker run --rm \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-v "${DEPLOY_DIR}:${DEPLOY_DIR}" \
|
||||||
|
-w "${DEPLOY_DIR}" \
|
||||||
|
docker:27-cli \
|
||||||
|
sh -c "
|
||||||
|
set -e
|
||||||
|
COMPOSE_FILES='-f docker-compose.yml -f docker-compose.hetzner.yml'
|
||||||
|
|
||||||
|
echo '=== Building Docker Images ==='
|
||||||
|
docker compose \${COMPOSE_FILES} build --parallel \
|
||||||
|
backend-core consent-service rag-service embedding-service health-aggregator
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
echo '=== Starting infrastructure ==='
|
||||||
|
docker compose \${COMPOSE_FILES} up -d postgres valkey qdrant minio mailpit
|
||||||
|
|
||||||
|
echo 'Warte auf DB + Cache...'
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
echo '=== Starting Ollama + pulling bge-m3 ==='
|
||||||
|
docker compose \${COMPOSE_FILES} up -d ollama
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# bge-m3 Modell pullen (nur beim ersten Mal ~670MB)
|
||||||
|
echo 'Pulling bge-m3 model (falls noch nicht vorhanden)...'
|
||||||
|
docker exec bp-core-ollama ollama pull bge-m3 2>&1 || echo 'WARNUNG: bge-m3 pull fehlgeschlagen (wird spaeter nachgeholt)'
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
echo '=== Starting application services ==='
|
||||||
|
docker compose \${COMPOSE_FILES} up -d \
|
||||||
|
embedding-service rag-service backend-core consent-service health-aggregator
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
echo '=== Health Checks ==='
|
||||||
|
sleep 15
|
||||||
|
for svc in bp-core-postgres bp-core-valkey bp-core-qdrant bp-core-ollama bp-core-embedding-service bp-core-rag-service bp-core-backend bp-core-consent-service bp-core-health; do
|
||||||
|
STATUS=\$(docker inspect --format='{{.State.Status}}' \"\${svc}\" 2>/dev/null || echo 'not found')
|
||||||
|
echo \"\${svc}: \${STATUS}\"
|
||||||
|
done
|
||||||
|
"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Deploy abgeschlossen: ${SHORT_SHA} ==="
|
||||||
|
|||||||
@@ -7,12 +7,10 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: docker
|
runs-on: ubuntu-latest
|
||||||
container: alpine:latest
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy via Coolify API
|
- name: Deploy via Coolify API
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache curl
|
|
||||||
echo "Deploying breakpilot-core to Coolify..."
|
echo "Deploying breakpilot-core to Coolify..."
|
||||||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
-X POST \
|
-X POST \
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ services:
|
|||||||
- breakpilot-network
|
- breakpilot-network
|
||||||
|
|
||||||
# =========================================================
|
# =========================================================
|
||||||
# OCR SERVICE (PaddleOCR PP-OCRv5)
|
# OCR SERVICE (PaddleOCR PP-OCRv5 Latin)
|
||||||
# =========================================================
|
# =========================================================
|
||||||
paddleocr-service:
|
paddleocr-service:
|
||||||
build:
|
build:
|
||||||
@@ -157,12 +157,10 @@ services:
|
|||||||
FLAGS_use_mkldnn: "0"
|
FLAGS_use_mkldnn: "0"
|
||||||
volumes:
|
volumes:
|
||||||
- paddleocr_models:/root/.paddleocr
|
- paddleocr_models:/root/.paddleocr
|
||||||
labels:
|
|
||||||
- "traefik.http.services.paddleocr.loadbalancer.server.port=8095"
|
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
memory: 6G
|
memory: 4G
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://127.0.0.1:8095/health"]
|
test: ["CMD", "curl", "-f", "http://127.0.0.1:8095/health"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""PaddleOCR Remote Service — PP-OCRv4 on x86_64 (CPU)."""
|
"""PaddleOCR Remote Service — PP-OCRv5 Latin auf x86_64."""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
@@ -27,22 +27,31 @@ def _load_model():
|
|||||||
logger.info("Importing paddleocr...")
|
logger.info("Importing paddleocr...")
|
||||||
from paddleocr import PaddleOCR
|
from paddleocr import PaddleOCR
|
||||||
|
|
||||||
logger.info("Loading PaddleOCR model (PP-OCRv4, lang=en)...")
|
logger.info("Import done. Loading PaddleOCR model...")
|
||||||
_engine = PaddleOCR(
|
# Try multiple init strategies for different PaddleOCR versions
|
||||||
lang="en",
|
inits = [
|
||||||
use_angle_cls=True,
|
# PaddleOCR 3.x (no show_log)
|
||||||
show_log=False,
|
dict(lang="en", ocr_version="PP-OCRv5", use_angle_cls=True),
|
||||||
enable_mkldnn=False,
|
# PaddleOCR 3.x with show_log
|
||||||
use_gpu=False,
|
dict(lang="en", ocr_version="PP-OCRv5", use_angle_cls=True, show_log=False),
|
||||||
)
|
# PaddleOCR 2.8+ (latin)
|
||||||
logger.info("PaddleOCR model loaded — running warmup...")
|
dict(lang="latin", use_angle_cls=True, show_log=False),
|
||||||
# Warmup with tiny image to trigger any lazy init
|
# PaddleOCR 2.8+ (en, no version)
|
||||||
dummy = np.ones((30, 100, 3), dtype=np.uint8) * 255
|
dict(lang="en", use_angle_cls=True, show_log=False),
|
||||||
_engine.ocr(dummy)
|
]
|
||||||
|
for i, kwargs in enumerate(inits):
|
||||||
|
try:
|
||||||
|
_engine = PaddleOCR(**kwargs)
|
||||||
|
logger.info(f"PaddleOCR init succeeded with strategy {i}: {kwargs}")
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
logger.info(f"PaddleOCR init strategy {i} failed: {e}")
|
||||||
|
else:
|
||||||
|
raise RuntimeError("All PaddleOCR init strategies failed")
|
||||||
_ready = True
|
_ready = True
|
||||||
logger.info("PaddleOCR ready to serve")
|
logger.info("PaddleOCR model loaded successfully — ready to serve")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to load PaddleOCR: {e}", exc_info=True)
|
logger.error(f"Failed to load PaddleOCR model: {e}")
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
@@ -50,14 +59,15 @@ def startup_load_model():
|
|||||||
"""Start model loading in background so health check passes immediately."""
|
"""Start model loading in background so health check passes immediately."""
|
||||||
global _loading
|
global _loading
|
||||||
_loading = True
|
_loading = True
|
||||||
threading.Thread(target=_load_model, daemon=True).start()
|
thread = threading.Thread(target=_load_model, daemon=True)
|
||||||
|
thread.start()
|
||||||
logger.info("Model loading started in background thread")
|
logger.info("Model loading started in background thread")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
def health():
|
def health():
|
||||||
if _ready:
|
if _ready:
|
||||||
return {"status": "ok", "model": "PP-OCRv4"}
|
return {"status": "ok", "model": "PP-OCRv5-latin"}
|
||||||
if _loading:
|
if _loading:
|
||||||
return {"status": "loading"}
|
return {"status": "loading"}
|
||||||
return {"status": "error"}
|
return {"status": "error"}
|
||||||
@@ -78,30 +88,25 @@ async def ocr(
|
|||||||
img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
|
img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
|
||||||
img_np = np.array(img)
|
img_np = np.array(img)
|
||||||
|
|
||||||
try:
|
result = _engine.ocr(img_np)
|
||||||
result = _engine.ocr(img_np)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"OCR failed: {e}", exc_info=True)
|
|
||||||
raise HTTPException(status_code=500, detail=f"OCR failed: {e}")
|
|
||||||
|
|
||||||
if not result or not result[0]:
|
|
||||||
return {"words": [], "image_width": img_np.shape[1], "image_height": img_np.shape[0]}
|
|
||||||
|
|
||||||
words = []
|
words = []
|
||||||
for line in result[0]:
|
for line in result[0] or []:
|
||||||
box, (text, conf) = line[0], line[1]
|
box, (text, conf) = line[0], line[1]
|
||||||
x_min = min(p[0] for p in box)
|
x_min = min(p[0] for p in box)
|
||||||
y_min = min(p[1] for p in box)
|
y_min = min(p[1] for p in box)
|
||||||
x_max = max(p[0] for p in box)
|
x_max = max(p[0] for p in box)
|
||||||
y_max = max(p[1] for p in box)
|
y_max = max(p[1] for p in box)
|
||||||
words.append({
|
words.append(
|
||||||
"text": str(text).strip(),
|
{
|
||||||
"left": int(x_min),
|
"text": text.strip(),
|
||||||
"top": int(y_min),
|
"left": int(x_min),
|
||||||
"width": int(x_max - x_min),
|
"top": int(y_min),
|
||||||
"height": int(y_max - y_min),
|
"width": int(x_max - x_min),
|
||||||
"conf": round(float(conf) * 100, 1),
|
"height": int(y_max - y_min),
|
||||||
})
|
"conf": round(conf * 100, 1),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"words": words,
|
"words": words,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
paddlepaddle>=2.6.0,<3.0.0
|
paddlepaddle>=3.0.0
|
||||||
paddleocr>=2.7.0,<3.0.0
|
paddleocr>=2.9.0
|
||||||
fastapi>=0.110.0
|
fastapi>=0.110.0
|
||||||
uvicorn>=0.25.0
|
uvicorn>=0.25.0
|
||||||
python-multipart>=0.0.6
|
python-multipart>=0.0.6
|
||||||
|
|||||||
Reference in New Issue
Block a user