This commit is contained in:
2025-12-27 01:27:44 +01:00
parent aa1f5e30d9
commit 592914ae37
4 changed files with 60 additions and 14 deletions

View File

@@ -7,8 +7,8 @@ set -e
echo "🚀 Starting TestArena Deployment..." echo "🚀 Starting TestArena Deployment..."
# 1. Install Dependencies # 1. Install System Dependencies
echo "📦 Installing dependencies..." echo "📦 Installing system dependencies..."
apt-get update apt-get update
apt-get install -y nginx python3-pip python3-venv apt-get install -y nginx python3-pip python3-venv
@@ -16,13 +16,18 @@ apt-get install -y nginx python3-pip python3-venv
echo "🐍 Setting up Python environment..." echo "🐍 Setting up Python environment..."
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
pip install fastapi uvicorn sqlalchemy pip install --upgrade pip
pip install fastapi uvicorn sqlalchemy pydantic
# 3. Configure Nginx # 3. Configure Nginx
echo "🌐 Configuring Nginx..." echo "🌐 Configuring Nginx..."
if [ -d "nginx" ] && [ -f "nginx/testarena.conf" ]; then
cp nginx/testarena.conf /etc/nginx/sites-available/testarena cp nginx/testarena.conf /etc/nginx/sites-available/testarena
ln -sf /etc/nginx/sites-available/testarena /etc/nginx/sites-enabled/ ln -sf /etc/nginx/sites-available/testarena /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default rm -f /etc/nginx/sites-enabled/default
else
echo "⚠️ Nginx configuration not found, skipping..."
fi
# 4. Create Data Directory # 4. Create Data Directory
echo "📁 Creating data directory..." echo "📁 Creating data directory..."
@@ -30,15 +35,25 @@ mkdir -p /home/asf/testarena
chown -R asf:asf /home/asf/testarena chown -R asf:asf /home/asf/testarena
chmod -R 755 /home/asf/testarena chmod -R 755 /home/asf/testarena
# 5. Restart Nginx # 5. Set up Systemd Services
echo "🔄 Restarting Nginx..." echo "⚙️ Setting up Systemd services..."
nginx -t cp testarena-app.service /etc/systemd/system/
systemctl restart nginx 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
echo "✅ Deployment complete!" echo "✅ Deployment complete!"
echo "--------------------------------------------------" echo "--------------------------------------------------"
echo "Dashboard: http://asf-server.duckdns.org:8080/" echo "Dashboard: http://asf-server.duckdns.org:8080/"
echo "Results: http://asf-server.duckdns.org:8080/results/" echo "Results: http://asf-server.duckdns.org:8080/results/"
echo "--------------------------------------------------" echo "--------------------------------------------------"
echo "To start the app: source venv/bin/activate && uvicorn testarena_app.main:app --host 0.0.0.0 --port 8000" echo "Services status:"
echo "To start the worker: source venv/bin/activate && python3 -m testarena_app.worker" systemctl status testarena-app --no-pager || true
systemctl status testarena-worker --no-pager || true

15
testarena-app.service Normal file
View File

@@ -0,0 +1,15 @@
[Unit]
Description=TestArena FastAPI Application
After=network.target
[Service]
User=asf
Group=asf
WorkingDirectory=/home/asf/testarena_backend
Environment="PATH=/home/asf/testarena_backend/venv/bin"
Environment="DATABASE_URL=sqlite:////home/asf/testarena/testarena.db"
ExecStart=/home/asf/testarena_backend/venv/bin/uvicorn testarena_app.main:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target

15
testarena-worker.service Normal file
View File

@@ -0,0 +1,15 @@
[Unit]
Description=TestArena Background Worker
After=network.target testarena-app.service
[Service]
User=asf
Group=asf
WorkingDirectory=/home/asf/testarena_backend
Environment="PATH=/home/asf/testarena_backend/venv/bin"
Environment="DATABASE_URL=sqlite:////home/asf/testarena/testarena.db"
ExecStart=/home/asf/testarena_backend/venv/bin/python3 -m testarena_app.worker
Restart=always
[Install]
WantedBy=multi-user.target

View File

@@ -1,9 +1,10 @@
from sqlalchemy import create_all_engines, create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
import os import os
# Using SQLite for simplicity as requested # Using SQLite for simplicity as requested
DATABASE_URL = "sqlite:///d:/ASF - course/ASF_01/ASF_tools/asf-pc-server/testarena_pc_backend/testarena_app/testarena.db" # Use environment variable for database path or default to a relative path
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./testarena.db")
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)