From bd1d56e1d0a0c37cc9bc84821672037a241505be Mon Sep 17 00:00:00 2001 From: mahmamdouh Date: Mon, 24 Nov 2025 20:39:18 +0100 Subject: [PATCH] update for pc server --- asf-cloud-server/testarena/Caddyfile | 31 --------- asf-cloud-server/testarena/README.md | 67 +++++++++++-------- asf-cloud-server/testarena/docker-compose.yml | 29 +------- asf-cloud-server/testarena/frontend/Caddyfile | 6 -- .../testarena/frontend/Dockerfile | 10 --- .../testarena/nginx_config_snippet.conf | 54 +++++++++++++++ 6 files changed, 96 insertions(+), 101 deletions(-) delete mode 100644 asf-cloud-server/testarena/Caddyfile delete mode 100644 asf-cloud-server/testarena/frontend/Caddyfile delete mode 100644 asf-cloud-server/testarena/frontend/Dockerfile create mode 100644 asf-cloud-server/testarena/nginx_config_snippet.conf diff --git a/asf-cloud-server/testarena/Caddyfile b/asf-cloud-server/testarena/Caddyfile deleted file mode 100644 index c39316e..0000000 --- a/asf-cloud-server/testarena/Caddyfile +++ /dev/null @@ -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 - } -} diff --git a/asf-cloud-server/testarena/README.md b/asf-cloud-server/testarena/README.md index a39907c..f97e613 100644 --- a/asf-cloud-server/testarena/README.md +++ b/asf-cloud-server/testarena/README.md @@ -13,42 +13,55 @@ A full-stack web application to manage automated software test jobs. - **Backend**: FastAPI (Python) - **Frontend**: React + Vite (TypeScript) - **Database**: PostgreSQL -- **Reverse Proxy**: Caddy -- **Containerization**: Docker Compose +- **Reverse Proxy**: Nginx (Local Host) +- **Containerization**: Docker Compose (Backend + DB) ## Deployment Instructions ### Prerequisites -- Docker and Docker Compose installed on the server. -- Domain `testarena.nabd-co.com` pointing to the server IP. +- Docker and Docker Compose installed. +- Nginx installed on the host machine. +- Node.js installed (to build frontend). +- Domain `asf-testarena.duckdns.org` pointing to your PC. -### Steps -1. **Clone the repository** to your VPS. - ```bash - git clone - cd testarena - ``` +### 1. Backend & Database +Start the backend and database using Docker Compose: +```bash +docker-compose up -d --build +``` +This will expose the backend API on `localhost:8000`. -2. **Configure Environment** - - Edit `docker-compose.yml` if you need to change database passwords. - - Edit `backend/app/auth.py` to change the `SECRET_KEY`. +### 2. Frontend +Build the frontend application: +```bash +cd frontend +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. **Run with Docker Compose** - ```bash - docker-compose up -d --build - ``` +### 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`. -4. **Verify** - - Open `https://testarena.nabd-co.com` in your browser. - - Login with default credentials: - - Username: `admin` - - Password: `admin123` +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 - The mock scripts are located in `backend/scripts/`. - Replace `get_scenarios.sh` and `run_tests.sh` with your actual implementation. -- Ensure the scripts are executable (`chmod +x`). - -### Troubleshooting -- Check logs: `docker-compose logs -f` -- Restart services: `docker-compose restart` +- Ensure the scripts are executable. diff --git a/asf-cloud-server/testarena/docker-compose.yml b/asf-cloud-server/testarena/docker-compose.yml index 6124be7..2c4a5af 100644 --- a/asf-cloud-server/testarena/docker-compose.yml +++ b/asf-cloud-server/testarena/docker-compose.yml @@ -19,6 +19,8 @@ services: volumes: - ./backend:/app - ./results:/results + ports: + - "8000:8000" environment: - DATABASE_URL=postgresql://user:password@db/testarena - SCRIPTS_DIR=/app/scripts @@ -28,36 +30,9 @@ services: - app-network 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: app-network: driver: bridge volumes: postgres_data: - caddy_data: - caddy_config: diff --git a/asf-cloud-server/testarena/frontend/Caddyfile b/asf-cloud-server/testarena/frontend/Caddyfile deleted file mode 100644 index 5aa8d39..0000000 --- a/asf-cloud-server/testarena/frontend/Caddyfile +++ /dev/null @@ -1,6 +0,0 @@ -:80 { - root * /srv - encode gzip - file_server - try_files {path} /index.html -} diff --git a/asf-cloud-server/testarena/frontend/Dockerfile b/asf-cloud-server/testarena/frontend/Dockerfile deleted file mode 100644 index 2ab4b5c..0000000 --- a/asf-cloud-server/testarena/frontend/Dockerfile +++ /dev/null @@ -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 diff --git a/asf-cloud-server/testarena/nginx_config_snippet.conf b/asf-cloud-server/testarena/nginx_config_snippet.conf new file mode 100644 index 0000000..8f8f87a --- /dev/null +++ b/asf-cloud-server/testarena/nginx_config_snippet.conf @@ -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; + } +}