Files
mindnet/deploy/deploy.sh
T
LarsandClaude Opus 5.5 8f9f83aa79 Add reachability checks and develop/main container pipeline (inactive)
- preflight --live: Ollama/Qdrant reachable from the container, required
  Ollama models present, 768 dimensions; clear abort instead of traceback.
  Static check rejects unset or container-local service URLs.
- deploy/smoke.py: non-writing post-start check via published ports.
- deploy/deploy.sh: test (no network), build, preflight, up --wait, smoke;
  prod rolls back to the last good image tag.
- Workflow templates deploy-dev.yml (push develop) and deploy-prod.yml
  (push main) following the Kansho pattern; not under .gitea/workflows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 16:01:37 +01:00

90 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Baut, prüft und startet einen Mindnet-Container-Stack. Genutzt von den
# Gitea-Workflows (develop -> dev, main -> prod) und für manuelle Deploys.
#
# MINDNET_ENV_FILE=/home/llmadmin/docker/mindnet-dev/dev.env deploy/deploy.sh dev
#
# Ablauf (jeder Schritt bricht ab, bevor der laufende Stack angefasst wird):
# 1. Container-Tests im Test-Image, ohne Netzwerk (blockierend)
# 2. volle Testsuite ohne Netzwerk (informativ, bekannte Fehler siehe Migrationsplan)
# 3. Image bauen, Tag = Umgebung + Commit
# 4. preflight --live: Ollama/Qdrant erreichbar, Modelle, 768 Dimensionen, Vault (nur lesend)
# 5. up --wait (Healthchecks), danach smoke.py über die veröffentlichten Ports
# 6. Prod: bei Fehler Rückkehr zum letzten erfolgreichen Tag
#
# Die env-Datei liegt auf dem Host außerhalb von Git; in ihrem Verzeichnis
# merkt sich das Skript den letzten erfolgreichen Image-Tag (last_good_tag).
set -euo pipefail
cd "$(dirname "$0")/.."
ENV="${1:-}"
case "$ENV" in
dev|prod) ;;
*) echo "Aufruf: deploy/deploy.sh dev|prod" >&2; exit 2 ;;
esac
: "${MINDNET_ENV_FILE:?MINDNET_ENV_FILE auf die env-Datei des Hosts setzen}"
[ -f "$MINDNET_ENV_FILE" ] || { echo "env-Datei fehlt: $MINDNET_ENV_FILE" >&2; exit 1; }
export MINDNET_ENV_FILE
SHA="$(git rev-parse --short=12 HEAD)"
export MINDNET_IMAGE_TAG="$ENV-$SHA"
LAST_GOOD="$(dirname "$MINDNET_ENV_FILE")/last_good_tag"
if [ "$ENV" = dev ]; then
PREFIX=mindnet_dev
RUN_DEPS=() # startet die eigene Dev-Qdrant für den Preflight mit
SMOKE_ARGS=()
else
PREFIX="$(sed -n 's/^COLLECTION_PREFIX=//p' "$MINDNET_ENV_FILE" | tail -n 1)"
RUN_DEPS=(--no-deps) # Prod hat keine eigene Qdrant
SMOKE_ARGS=(--require-data)
fi
dc() { docker compose -f "deploy/compose.$ENV.yml" --env-file "$MINDNET_ENV_FILE" "$@"; }
step() { printf '\n=== %s\n' "$*"; }
show_logs() { dc ps || true; dc logs --tail 150 api ui || true; }
published() { dc port "$1" "$2" | head -n 1 | sed 's/^0\.0\.0\.0:/127.0.0.1:/'; }
smoke() {
python3 deploy/smoke.py --api "http://$(published api 8000)" --ui "http://$(published ui 8501)" \
--prefix "$PREFIX" "${SMOKE_ARGS[@]}"
}
step "1/5 Container-Tests (ohne Netzwerk)"
docker build -f deploy/Dockerfile --target test -t "mindnet:test-$SHA" .
docker run --rm --network none "mindnet:test-$SHA"
step "2/5 Volle Testsuite (informativ, ohne Netzwerk)"
if ! docker run --rm --network none "mindnet:test-$SHA" \
python -m pytest tests -q -p no:cacheprovider --continue-on-collection-errors --basetemp=/tmp/pytest; then
echo "WARNUNG: Testsuite nicht grün. Bekannte Fehler: docs/05_Development/05_docker_migration_plan.md"
fi
docker image rm "mindnet:test-$SHA" >/dev/null || true
step "3/5 Image bauen ($MINDNET_IMAGE_TAG)"
dc build api ui
step "4/5 Preflight mit Erreichbarkeit (nur lesend)"
dc run --rm "${RUN_DEPS[@]}" api preflight --live
step "5/5 Start ($MINDNET_IMAGE_TAG) und Smoke"
if dc up -d --wait --no-build && smoke; then
echo "$MINDNET_IMAGE_TAG" > "$LAST_GOOD"
echo "=== mindnet-$ENV läuft mit $MINDNET_IMAGE_TAG"
exit 0
fi
show_logs
PREV="$(cat "$LAST_GOOD" 2>/dev/null || true)"
if [ "$ENV" = prod ] && [ -n "$PREV" ] && [ "$PREV" != "$MINDNET_IMAGE_TAG" ]; then
step "Rollback auf $PREV"
export MINDNET_IMAGE_TAG="$PREV"
if dc up -d --wait --no-build && smoke; then
echo "Rollback erfolgreich; Deploy von $ENV-$SHA ist trotzdem fehlgeschlagen."
else
show_logs
echo "ROLLBACK FEHLGESCHLAGEN, manueller Eingriff nötig." >&2
fi
fi
exit 1