86 lines
2.7 KiB
Bash
86 lines
2.7 KiB
Bash
#!/bin/bash
|
||
|
||
# TestArena Deployment Script
|
||
# Run this script with sudo: sudo ./deploy.sh
|
||
|
||
set -e
|
||
|
||
# Check if running as root
|
||
if [ "$EUID" -ne 0 ]; then
|
||
echo "❌ Please run as root (use sudo ./deploy.sh)"
|
||
exit 1
|
||
fi
|
||
|
||
echo "🚀 Starting TestArena Deployment..."
|
||
|
||
# 1. Install System Dependencies
|
||
echo "📦 Installing system dependencies..."
|
||
apt-get update
|
||
apt-get install -y nginx python3-pip python3-venv sqlite3
|
||
|
||
# 1.1 Database Migration (Add source column if missing)
|
||
echo "🗄️ Checking database schema..."
|
||
DB_PATH="/home/asf/testarena/testarena.db"
|
||
if [ -f "$DB_PATH" ]; then
|
||
if ! sqlite3 "$DB_PATH" ".schema queues" | grep -q "source"; then
|
||
echo "➕ Adding 'source' column to 'queues' table..."
|
||
sqlite3 "$DB_PATH" "ALTER TABLE queues ADD COLUMN source TEXT;"
|
||
fi
|
||
fi
|
||
|
||
# 2. Set up Python Virtual Environment
|
||
echo "🐍 Setting up Python environment..."
|
||
python3 -m venv venv
|
||
source venv/bin/activate
|
||
pip install --upgrade pip
|
||
pip install fastapi uvicorn sqlalchemy pydantic
|
||
|
||
# 3. Configure Nginx
|
||
echo "🌐 Configuring Nginx..."
|
||
if [ -d "nginx" ] && [ -f "nginx/testarena.conf" ]; then
|
||
cp nginx/testarena.conf /etc/nginx/sites-available/testarena
|
||
ln -sf /etc/nginx/sites-available/testarena /etc/nginx/sites-enabled/
|
||
rm -f /etc/nginx/sites-enabled/default
|
||
else
|
||
echo "⚠️ Nginx configuration not found, skipping..."
|
||
fi
|
||
|
||
# 4. Create Data and TPF Directories
|
||
echo "📁 Creating directories..."
|
||
mkdir -p /home/asf/testarena
|
||
mkdir -p /home/asf/testarena_backend/TPF
|
||
chown -R asf:asf /home/asf/testarena
|
||
chown -R asf:asf /home/asf/testarena_backend/TPF
|
||
chmod -R 755 /home/asf/testarena
|
||
chmod -R 755 /home/asf/testarena_backend/TPF
|
||
|
||
# Copy scripts to TPF
|
||
cp gitea_repo_controller.sh /home/asf/testarena_backend/TPF/
|
||
cp scenario_execution.py /home/asf/testarena_backend/TPF/
|
||
cp scenario_exe_parser.py /home/asf/testarena_backend/TPF/
|
||
cp test_execution.sh /home/asf/testarena_backend/TPF/
|
||
chmod +x /home/asf/testarena_backend/TPF/*.sh
|
||
|
||
# 5. Set up Systemd Services
|
||
echo "⚙️ Setting up Systemd services..."
|
||
cp testarena-app.service /etc/systemd/system/
|
||
cp testarena-worker.service /etc/systemd/system/
|
||
systemctl daemon-reload
|
||
systemctl enable testarena-app
|
||
systemctl enable testarena-worker
|
||
|
||
# 6. Restart Services
|
||
echo "🔄 Restarting services..."
|
||
nginx -t && systemctl restart nginx
|
||
systemctl restart testarena-app
|
||
systemctl restart testarena-worker
|
||
sudo ufw allow 8080
|
||
echo "✅ Deployment complete!"
|
||
echo "--------------------------------------------------"
|
||
echo "Dashboard: http://asf-server.duckdns.org:8080/"
|
||
echo "Results: http://asf-server.duckdns.org:8080/results/"
|
||
echo "--------------------------------------------------"
|
||
echo "Services status:"
|
||
systemctl status testarena-app --no-pager || true
|
||
systemctl status testarena-worker --no-pager || true
|