update for pc server

This commit is contained in:
2025-11-24 20:39:18 +01:00
parent 4df7501aba
commit bd1d56e1d0
6 changed files with 96 additions and 101 deletions

View File

@@ -1,31 +0,0 @@
testarena.nabd-co.com {
# API and Auth
handle /api/* {
reverse_proxy backend:8000
}
handle /auth/* {
reverse_proxy backend:8000
}
handle /admin/* {
reverse_proxy backend:8000
}
handle /jobs/* {
reverse_proxy backend:8000
}
# WebSocket
handle /ws/* {
reverse_proxy backend:8000
}
# Results (Mounted volume)
handle /results/* {
root * /srv
file_server
}
# Frontend
handle {
reverse_proxy frontend:80
}
}

View File

@@ -13,42 +13,55 @@ A full-stack web application to manage automated software test jobs.
- **Backend**: FastAPI (Python) - **Backend**: FastAPI (Python)
- **Frontend**: React + Vite (TypeScript) - **Frontend**: React + Vite (TypeScript)
- **Database**: PostgreSQL - **Database**: PostgreSQL
- **Reverse Proxy**: Caddy - **Reverse Proxy**: Nginx (Local Host)
- **Containerization**: Docker Compose - **Containerization**: Docker Compose (Backend + DB)
## Deployment Instructions ## Deployment Instructions
### Prerequisites ### Prerequisites
- Docker and Docker Compose installed on the server. - Docker and Docker Compose installed.
- Domain `testarena.nabd-co.com` pointing to the server IP. - Nginx installed on the host machine.
- Node.js installed (to build frontend).
- Domain `asf-testarena.duckdns.org` pointing to your PC.
### Steps ### 1. Backend & Database
1. **Clone the repository** to your VPS. Start the backend and database using Docker Compose:
```bash
git clone <repo_url>
cd testarena
```
2. **Configure Environment**
- Edit `docker-compose.yml` if you need to change database passwords.
- Edit `backend/app/auth.py` to change the `SECRET_KEY`.
3. **Run with Docker Compose**
```bash ```bash
docker-compose up -d --build docker-compose up -d --build
``` ```
This will expose the backend API on `localhost:8000`.
4. **Verify** ### 2. Frontend
- Open `https://testarena.nabd-co.com` in your browser. Build the frontend application:
- Login with default credentials: ```bash
- Username: `admin` cd frontend
- Password: `admin123` npm install
npm run build
```
Copy the contents of `frontend/dist` to your web root:
```bash
# Example path based on your request
sudo cp -r dist/* /var/www/testarena/
```
### 3. Nginx Configuration
Update your Nginx configuration (usually in `/etc/nginx/sites-available/default` or similar) using the snippet provided in `nginx_config_snippet.conf`.
Key configurations:
- Serve static files from `/var/www/testarena`.
- Proxy `/api/`, `/auth/`, `/admin/`, `/jobs/`, `/ws/` to `http://localhost:8000`.
- Alias `/results/` to the `results` folder in this project directory.
Restart Nginx:
```bash
sudo systemctl restart nginx
```
### 4. Verify
- Open `http://asf-testarena.duckdns.org`.
- Login with `admin` / `admin123`.
### Scripts Integration ### Scripts Integration
- The mock scripts are located in `backend/scripts/`. - The mock scripts are located in `backend/scripts/`.
- Replace `get_scenarios.sh` and `run_tests.sh` with your actual implementation. - Replace `get_scenarios.sh` and `run_tests.sh` with your actual implementation.
- Ensure the scripts are executable (`chmod +x`). - Ensure the scripts are executable.
### Troubleshooting
- Check logs: `docker-compose logs -f`
- Restart services: `docker-compose restart`

View File

@@ -19,6 +19,8 @@ services:
volumes: volumes:
- ./backend:/app - ./backend:/app
- ./results:/results - ./results:/results
ports:
- "8000:8000"
environment: environment:
- DATABASE_URL=postgresql://user:password@db/testarena - DATABASE_URL=postgresql://user:password@db/testarena
- SCRIPTS_DIR=/app/scripts - SCRIPTS_DIR=/app/scripts
@@ -28,36 +30,9 @@ services:
- app-network - app-network
restart: always restart: always
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
networks:
- app-network
restart: always
caddy:
image: caddy:2
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./results:/srv/results
- caddy_data:/data
- caddy_config:/config
depends_on:
- backend
- frontend
networks:
- app-network
restart: always
networks: networks:
app-network: app-network:
driver: bridge driver: bridge
volumes: volumes:
postgres_data: postgres_data:
caddy_data:
caddy_config:

View File

@@ -1,6 +0,0 @@
:80 {
root * /srv
encode gzip
file_server
try_files {path} /index.html
}

View File

@@ -1,10 +0,0 @@
FROM node:18-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM caddy:2-alpine
COPY --from=build /app/dist /srv
COPY Caddyfile /etc/caddy/Caddyfile

View File

@@ -0,0 +1,54 @@
server {
listen 80;
server_name asf-testarena.duckdns.org;
# Frontend Static Files
location / {
root /var/www/testarena;
index index.html;
try_files $uri $uri/ /index.html;
}
# Backend API Proxy
location /api/ {
proxy_pass http://localhost:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /auth/ {
proxy_pass http://localhost:8000/auth/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /admin/ {
proxy_pass http://localhost:8000/admin/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /jobs/ {
proxy_pass http://localhost:8000/jobs/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# WebSocket Proxy
location /ws/ {
proxy_pass http://localhost:8000/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
# Results (Assuming you mount/copy results to this path or proxy to backend if it served them)
# The backend was configured to write to /results.
# Since we are running backend in docker, we mapped ./results to /results.
# You can alias this location to the local folder on your PC.
location /results/ {
alias /path/to/your/project/testarena/results/;
autoindex on;
}
}