glam/apps/archief-assistent/deploy-backend.sh
2025-12-21 00:01:54 +01:00

78 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# Deploy script for de Aa Archiefassistent Backend
set -e
SERVER="root@91.98.224.44"
BACKEND_PATH="/var/www/archief-assistent-api"
echo "🚀 Deploying de Aa Auth Backend..."
# Create directory on server
ssh $SERVER "mkdir -p $BACKEND_PATH"
# Copy files
echo "📦 Copying backend files..."
rsync -avz --exclude '__pycache__' --exclude '*.pyc' --exclude '.env' --exclude 'venv' \
backend/ $SERVER:$BACKEND_PATH/
# Setup virtual environment and install dependencies on server
echo "📚 Setting up virtual environment and installing dependencies..."
ssh $SERVER "cd $BACKEND_PATH && \
python3 -m venv venv && \
./venv/bin/pip install --upgrade pip && \
./venv/bin/pip install -r requirements.txt"
# Remind about .env
echo ""
echo "⚠️ IMPORTANT: Make sure to create .env on the server:"
echo " ssh $SERVER"
echo " cd $BACKEND_PATH"
echo " cp .env.example .env"
echo " nano .env # Add your real users and generate JWT secrets"
echo ""
# Create systemd service if it doesn't exist
ssh $SERVER "cat > /etc/systemd/system/de-aa-api.service << 'EOF'
[Unit]
Description=de Aa Authentication API
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/var/www/archief-assistent-api
EnvironmentFile=/var/www/archief-assistent-api/.env
ExecStart=/var/www/archief-assistent-api/venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8080
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF"
# Create a basic .env if it doesn't exist
ssh $SERVER "if [ ! -f $BACKEND_PATH/.env ]; then
cp $BACKEND_PATH/.env.example $BACKEND_PATH/.env
echo 'Created .env from .env.example - please configure it!'
fi"
# Reload and restart service
echo "🔄 Restarting service..."
ssh $SERVER "systemctl daemon-reload && systemctl enable de-aa-api && systemctl restart de-aa-api"
# Wait a moment for service to start
sleep 2
# Check status
echo ""
echo "📊 Service status:"
ssh $SERVER "systemctl status de-aa-api --no-pager || true"
echo ""
echo "✅ Backend deployed!"
echo ""
echo "Next steps:"
echo "1. Configure Caddy to proxy /auth/* → localhost:8080"
echo "2. Update .env file with real users"
echo "3. Restart the service: systemctl restart de-aa-api"