diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..68a4050 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e + +MODE="${1:-setup}" +SERVER="${2:-root@49.12.2.88}" +APP_DIR="/opt/satellite-fusion" +DATA_DIR="$APP_DIR/data" + +case "$MODE" in + setup) + echo "Deploying to $SERVER..." + TEMP_DIR=$(mktemp -d) + rsync -av --exclude='__pycache__' --exclude='*.pyc' --exclude='.git' --exclude='data/' --exclude='.env' . "$TEMP_DIR/" + cat > "$TEMP_DIR/.env.example" < /dev/null; then + apt-get update -qq + apt-get install -y python3.11 python3.11-venv python3.11-dev 2>/dev/null || { + apt-get install -y -t trixie-backports python3.11 python3.11-venv python3.11-dev 2>/dev/null || { + apt-get install -y software-properties-common + add-apt-repository -y ppa:deadsnakes/ppa 2>/dev/null || true + apt-get update -qq + apt-get install -y python3.11 python3.11-venv python3.11-dev + } + } +fi + +# Setup venv +[ -d venv ] && rm -rf venv +python3.11 -m venv venv +source venv/bin/activate +pip install --upgrade pip -q +pip install -r requirements.txt -q +pip install git+https://github.com/DHI-GRAS/efast.git -q + +# Setup .env +[ ! -f .env ] && [ -f .env.example ] && cp .env.example .env + +# Setup systemd service +if [ -f satellite-fusion-web.service ]; then + sed "s|/opt/satellite-fusion|$APP_DIR|g" satellite-fusion-web.service | \ + sed "s|--directory /opt/satellite-fusion|--directory $APP_DIR/webapp|g" > /tmp/satellite-fusion-web.service + cp /tmp/satellite-fusion-web.service /etc/systemd/system/ + systemctl daemon-reload +fi + +# Create data directory +mkdir -p $DATA_DIR +ENDSSH + echo "Setup complete!" + ;; + + upload) + echo "Uploading data to $SERVER..." + rsync -avh --progress --exclude='*.pyc' --exclude='__pycache__' data/ "$SERVER:$DATA_DIR/" + echo "Data upload complete!" + ;; + + *) + echo "Usage: $0 {setup|upload} [server]" + echo " setup - Deploy code and setup server (default)" + echo " upload - Upload data directory only" + exit 1 + ;; +esac diff --git a/satellite-fusion-web.service b/satellite-fusion-web.service new file mode 100644 index 0000000..7742678 --- /dev/null +++ b/satellite-fusion-web.service @@ -0,0 +1,16 @@ +[Unit] +Description=Satellite Fusion Pipeline Web Server +After=network.target + +[Service] +Type=simple +User=root +WorkingDirectory=/opt/satellite-fusion/webapp +Environment="PATH=/opt/satellite-fusion/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +ExecStart=/opt/satellite-fusion/venv/bin/python3 -m http.server 8000 --directory /opt/satellite-fusion/webapp +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target +