Files
LarsandClaude Opus 5.5 6cdad8b046 Run the containers with the systemd configuration, 1:1
The containers now read the unchanged .env of the matching systemd instance
(/home/llmadmin/mindnet_dev/.env, /home/llmadmin/mindnet/.env) and use the
same Qdrant, Ollama, vault and collection prefix, so both can be compared
side by side. Only container-specific values are overridden: host service
addresses (host.docker.internal instead of 127.0.0.1) and the read-only vault.

- deploy/appenv.py derives the vault mount and prefix from that .env and
  rejects application keys in the container-only file.
- Remove the separate dev Qdrant, the synthetic test vault and the import step.
- UI binds 0.0.0.0 like systemd; API stays loopback by default.

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

93 lines
3.8 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_APP_ENV_FILE=/home/llmadmin/mindnet_dev/.env # MINDNET_ENV_FILE=/home/llmadmin/docker/mindnet-dev/container.env deploy/deploy.sh dev
#
# MINDNET_APP_ENV_FILE ist die unveränderte .env der systemd-Instanz (gleiche Konfiguration),
# MINDNET_ENV_FILE enthält nur Container-Angaben (deploy/env/<env>.env.example).
#
# 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
#
# Beide Dateien liegen auf dem Host außerhalb von Git; im Verzeichnis der Container-Datei
# 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_APP_ENV_FILE:?MINDNET_APP_ENV_FILE auf die .env der systemd-Instanz setzen}"
: "${MINDNET_ENV_FILE:?MINDNET_ENV_FILE auf die Container-Datei des Hosts setzen}"
for f in "$MINDNET_APP_ENV_FILE" "$MINDNET_ENV_FILE"; do
[ -f "$f" ] || { echo "env-Datei fehlt: $f" >&2; exit 1; }
done
export MINDNET_APP_ENV_FILE MINDNET_ENV_FILE
# Vault-Mount und Präfix aus der systemd-.env ableiten (gleiches Verzeichnis wie heute).
DERIVED="$(python3 deploy/appenv.py "$MINDNET_APP_ENV_FILE" "$MINDNET_ENV_FILE")"
eval "$DERIVED"
export MINDNET_VAULT_HOST_PATH MINDNET_VAULT_TARGET
PREFIX="$MINDNET_EXPECTED_PREFIX"
echo "$DERIVED"
SHA="$(git rev-parse --short=12 HEAD)"
export MINDNET_IMAGE_TAG="$ENV-$SHA"
LAST_GOOD="$(dirname "$MINDNET_ENV_FILE")/last_good_tag"
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" --require-data
}
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 --no-deps api preflight --live
step "5/5 Start ($MINDNET_IMAGE_TAG) und Smoke"
if dc up -d --wait --no-build --remove-orphans && 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 --remove-orphans && 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