38 lines
1.7 KiB
Bash
Executable File
38 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
umask 077
|
|
export DATA_DIR="${DATA_DIR:-/data}"
|
|
REPO_URL="${REPO_URL:-https://git.casaderoll.de/michael/CasaDePrompt.git}"
|
|
APP_REF="${APP_REF:-main}"
|
|
PUID="${PUID:-99}"
|
|
PGID="${PGID:-100}"
|
|
case "$PUID:$PGID" in *[!0-9:]*|:*|*:) echo 'PUID/PGID müssen numerisch sein.' >&2; exit 1;; esac
|
|
if [ "$(id -u)" = 0 ]; then
|
|
apk add --no-cache git ca-certificates su-exec
|
|
fi
|
|
mkdir -p "$DATA_DIR" /opt/casadeprompt
|
|
chmod 755 /opt/casadeprompt
|
|
if [ -n "${APP_SOURCE:-}" ]; then
|
|
APP_PATH="$APP_SOURCE"
|
|
else
|
|
case "$REPO_URL" in https://*) ;; *) echo "REPO_URL muss HTTPS verwenden." >&2; exit 1;; esac
|
|
case "$REPO_URL" in -*) echo 'Ungültige REPO_URL' >&2; exit 1;; esac
|
|
case "$APP_REF" in -*) echo 'Ungültige APP_REF' >&2; exit 1;; esac
|
|
APP_PATH="$(mktemp -d /opt/casadeprompt/release.XXXXXX)"
|
|
echo 'Lade CasaDePrompt aus dem Repository …'
|
|
git clone --quiet --depth 1 --branch "$APP_REF" -- "$REPO_URL" "$APP_PATH"
|
|
rm -rf "$APP_PATH/.git"
|
|
fi
|
|
[ -f "$APP_PATH/requirements.txt" ] && [ -f "$APP_PATH/atelier/app.py" ] || { echo 'Repository muss die Anwendung im Hauptverzeichnis enthalten.' >&2; exit 1; }
|
|
python -m venv /opt/casa-venv
|
|
/opt/casa-venv/bin/pip install --disable-pip-version-check --no-cache-dir -r "$APP_PATH/requirements.txt"
|
|
cd "$APP_PATH"
|
|
if [ "$(id -u)" = 0 ]; then
|
|
chown "$PUID:$PGID" "$DATA_DIR"
|
|
chmod 700 "$DATA_DIR"
|
|
chmod -R a+rX "$APP_PATH" /opt/casa-venv
|
|
echo 'Starte CasaDePrompt. Zugangsschlüssel liegt in /data/admin-token.'
|
|
exec su-exec "$PUID:$PGID" /opt/casa-venv/bin/uvicorn atelier.app:create_app --factory --host 0.0.0.0 --port "${PORT:-8000}" --no-access-log
|
|
fi
|
|
exec /opt/casa-venv/bin/uvicorn atelier.app:create_app --factory --host 0.0.0.0 --port "${PORT:-8000}" --no-access-log
|