Implement error handling in app.py, update deployment instructions in README_DASHBOARD.md, and modify deploy.sh for rsync-based deployment. Adjust base.html to safely access session variables.

This commit is contained in:
2026-02-18 08:30:38 +02:00
parent ff44ea4927
commit 9193f2a7b1
5 changed files with 70 additions and 42 deletions

8
deploy/deploy-from-pc.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Deploy from this PC via SSH: upload project with rsync, then setup/restart on server.
# Usage: ./deploy/deploy-from-pc.sh
# Requires: rsync, SSH access to root@10.110.60.210 (LXC has no Git access).
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$(dirname "$SCRIPT_DIR")"
exec "$SCRIPT_DIR/deploy.sh"

View File

@@ -1,44 +1,47 @@
#!/bin/bash
# Deploy Portal Auth Dashboard to root@10.110.60.210 from Git
# Repo: http://10.20.30.250:3000/nearxos/portal-auth-dashboard
# Deploy Portal Auth Dashboard to root@10.110.60.210 by uploading from this PC via SSH/rsync.
# LXC has no direct access to Git; run this script from your PC.
set -e
TARGET="root@10.110.60.210"
APP_DIR="/opt/portal-auth-dashboard"
# Set GIT_REPO_URL with credentials if clone/pull needs auth, e.g.:
# export GIT_REPO_URL="http://nearxos:YOUR_TOKEN@10.20.30.250:3000/nearxos/portal-auth-dashboard.git"
GIT_REPO_URL="${GIT_REPO_URL:-http://10.20.30.250:3000/nearxos/portal-auth-dashboard.git}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
echo "=== Deploying from Git: ${GIT_REPO_URL%%@*}@... ==="
# Escape single quotes for use inside single-quoted ssh string
GIT_REPO_URL_SAFE=$(echo "$GIT_REPO_URL" | sed "s/'/'\\\\''/g")
echo "=== Uploading project to $TARGET via rsync ==="
ssh "$TARGET" "mkdir -p $APP_DIR; command -v rsync >/dev/null 2>&1 || (apt-get update -qq && apt-get install -y rsync)"
rsync -av \
--exclude '.env' \
--exclude '.git' \
--exclude '__pycache__' \
--exclude '*.pyc' \
--exclude 'venv' \
"$PROJECT_DIR/" \
"$TARGET:$APP_DIR/"
echo "=== Setting up on server ==="
ssh "$TARGET" "set -e
APP_DIR='$APP_DIR'
GIT_REPO_URL='$GIT_REPO_URL_SAFE'
if [ ! -d \"\$APP_DIR\" ]; then
echo '=== First-time clone ==='
git clone \"\$GIT_REPO_URL\" \"\$APP_DIR\"
cd \"\$APP_DIR\"
cd \"\$APP_DIR\"
if [ ! -d venv ] || [ ! -f venv/bin/pip ]; then
echo 'Creating venv and installing dependencies...'
rm -rf venv
apt-get update -qq
command -v python3 >/dev/null 2>&1 || apt-get install -y python3
apt-get install -y python3-venv python3-pip
python3 -m venv venv
./venv/bin/pip install -r requirements.txt
if [ ! -f .env ]; then
[ -f deploy/.env.server ] && cp deploy/.env.server .env || true
grep -q 'REPLACE_WITH' .env 2>/dev/null && echo 'Edit .env on server: DB_AUTH_PASSWORD and SECRET_KEY' || true
fi
cp deploy/portal-auth-dashboard.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable portal-auth-dashboard
systemctl restart portal-auth-dashboard
else
echo '=== Updating from Git ==='
cd \"\$APP_DIR\"
git fetch origin
git reset --hard origin/main
echo 'Updating dependencies...'
./venv/bin/pip install -q -r requirements.txt
systemctl restart portal-auth-dashboard
fi
if [ ! -f .env ]; then
[ -f deploy/.env.server ] && cp deploy/.env.server .env || true
grep -q 'REPLACE_WITH' .env 2>/dev/null && echo 'Edit .env on server: DB_AUTH_PASSWORD and SECRET_KEY' || true
fi
cp deploy/portal-auth-dashboard.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable portal-auth-dashboard
systemctl restart portal-auth-dashboard
echo '=== Status ==='
systemctl status portal-auth-dashboard --no-pager"