From abd61798c7ed44c4d23561a784894000a8146ea3 Mon Sep 17 00:00:00 2001 From: zwitschi Date: Wed, 29 Apr 2026 11:52:12 +0200 Subject: [PATCH] Update service ports to 12015 for backend and 12016 for frontend; adjust configurations and documentation accordingly --- .gitignore | 3 ++- backend/Dockerfile | 4 +-- backend/app/main.py | 2 +- docs/7-deployment-view.md | 22 ++++++++-------- docs/deployment/coolify.md | 42 +++++++++++++++---------------- docs/deployment/docker-compose.md | 24 +++++++++--------- frontend/Dockerfile | 4 +-- frontend/app/config.py | 5 ++-- frontend/app/static/app.js | 2 +- nginx/coolify.conf | 4 +-- nginx/docker-compose.conf | 4 +-- 11 files changed, 59 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 996283e..021dc43 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ htmlcov/ Thumbs.db # instructions -.github/instructions/ \ No newline at end of file +.github/instructions/ +backend/data/ diff --git a/backend/Dockerfile b/backend/Dockerfile index 922daab..eee0067 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -16,7 +16,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Expose port -EXPOSE 12000 +EXPOSE 12015 # Run the application -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "12000"] +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "12015"] diff --git a/backend/app/main.py b/backend/app/main.py index 44c2d8b..c548ae1 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -30,7 +30,7 @@ app = FastAPI( app.add_middleware( CORSMiddleware, - allow_origins=[os.getenv("CORS_ORIGINS", "http://localhost:12001")], + allow_origins=[os.getenv("CORS_ORIGINS", "http://localhost:12016")], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], diff --git a/docs/7-deployment-view.md b/docs/7-deployment-view.md index 25b4de9..96d4d82 100644 --- a/docs/7-deployment-view.md +++ b/docs/7-deployment-view.md @@ -13,7 +13,7 @@ Describes: │ ┌─────────────┐ ┌────────────────────┐ │ │ │ frontend │ │ backend │ │ │ │ (Flask) │ │ (FastAPI) │ │ -│ │ :12001 │ │ :12000 │ │ +│ │ :12016 │ │ :12015 │ │ │ └──────┬──────┘ └─────────┬──────────┘ │ │ │ │ │ │ └────────┬──────────┘ │ @@ -33,8 +33,8 @@ Describes: | Building Block | Container / Process | Port | | --------------- | ---------------------------- | ----- | -| Flask frontend | `frontend` | 12001 | -| FastAPI backend | `backend` | 12000 | +| Flask frontend | `frontend` | 12016 | +| FastAPI backend | `backend` | 12015 | | DuckDB | File on host (`data/app.db`) | — | ## Infrastructure Level 2 @@ -50,25 +50,25 @@ All services are containerized and orchestrated with `docker compose`: │ │ Docker Network: app-network (bridge) │ │ │ │ ┌──────────────────────────────────────────────┐ │ │ │ │ │ Backend Container (FastAPI) │ │ │ -│ │ │ - Port: 12000 │ │ │ +│ │ │ - Port: 12015 │ │ │ │ │ │ - Service Name: backend │ │ │ │ │ │ - Volume Mount: /app/data ← host/data/ │ │ │ │ │ ├──────────────────────────────────────────────┤ │ │ │ │ │ Frontend Container (Flask) │ │ │ -│ │ │ - Port: 12001 │ │ │ +│ │ │ - Port: 12016 │ │ │ │ │ │ - Service Name: frontend │ │ │ │ │ │ - Depends on: backend (health check) │ │ │ │ │ ├──────────────────────────────────────────────┤ │ │ │ │ │ Nginx Container (Reverse Proxy) │ │ │ │ │ │ - Port: 80 (HTTP), 443 (HTTPS) │ │ │ │ │ │ - Config: nginx/docker-compose.conf │ │ │ -│ │ │ - Routes: /api/* → backend:12000 │ │ │ -│ │ │ / → frontend:12001 │ │ │ +│ │ │ - Routes: /api/* → backend:12015 │ │ │ +│ │ │ / → frontend:12016 │ │ │ │ │ └──────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────┘ │ │ ▲ │ │ Host Port Bindings │ -│ 80:80, 443:443, 12000:12000, 12001:12001 │ +│ 80:80, 443:443, 12015:12015, 12016:12016 │ └─────────────────────────────────────────────────────────────┘ │ Users / Internet @@ -79,7 +79,7 @@ All services are containerized and orchestrated with `docker compose`: 1. Ensure Docker and Docker Compose are installed 2. Create `.env` with required environment variables 3. Run: `docker compose up --build` -4. Access via browser at `http://localhost:12001` or through Nginx at `http://localhost:80` +4. Access via browser at `http://localhost:12016` or through Nginx at `http://localhost:80` **Benefits:** @@ -87,7 +87,7 @@ All services are containerized and orchestrated with `docker compose`: - **Simplicity**: Single command to start entire stack - **Portability**: Run on any system with Docker installed - **Persistence**: DuckDB data survives container restarts via volume mounts -- **Networking**: Service names enable automatic DNS resolution (backend:12000, frontend:12001) +- **Networking**: Service names enable automatic DNS resolution (backend:12015, frontend:12016) - **Observability**: Easy logging with `docker compose logs` **See**: [Docker Compose Deployment Guide](./deployment/docker-compose.md) for detailed instructions. @@ -101,6 +101,6 @@ If using Coolify instead of Docker Compose: 3. **Data Persistence**: Named volume keeps DuckDB data at `/app/data` 4. **Fallback Path**: Use separate Nixpacks services only when one-stack Compose deploy is not suitable -**Note**: In Compose-based Coolify deployment, frontend reaches backend through Docker DNS at `http://backend:12000`. In Nixpacks-based deployment, use Coolify internal networking or colocate both services. +**Note**: In Compose-based Coolify deployment, frontend reaches backend through Docker DNS at `http://backend:12015`. In Nixpacks-based deployment, use Coolify internal networking or colocate both services. **See**: [Coolify Deployment Guide](./deployment/coolify.md) for detailed instructions. diff --git a/docs/deployment/coolify.md b/docs/deployment/coolify.md index 277a228..3cd1a8f 100644 --- a/docs/deployment/coolify.md +++ b/docs/deployment/coolify.md @@ -32,13 +32,13 @@ The application consists of two Python services: | Service | Framework | Port | Description | | -------- | ----------------- | ----- | ------------------------------------------ | -| Backend | FastAPI + uvicorn | 12000 | REST API, auth, AI generation, DuckDB | -| Frontend | Flask + gunicorn | 12001 | SSR web UI, session auth, proxy to backend | +| Backend | FastAPI + uvicorn | 12015 | REST API, auth, AI generation, DuckDB | +| Frontend | Flask + gunicorn | 12016 | SSR web UI, session auth, proxy to backend | Coolify's built-in reverse proxy routes traffic: -- `/api/*` → Backend (port 12000) -- `/` → Frontend (port 12001) +- `/api/*` → Backend (port 12015) +- `/` → Frontend (port 12016) ## Prerequisites @@ -57,7 +57,7 @@ Use Coolify's **Docker Compose** resource with the dedicated compose file `docke 3. Select the `ai.allucanget.biz` repository and `main` branch 4. Set **Compose File** to `docker-compose.coolify.yml` 5. Set **Base Directory** to `/` -6. Select the `frontend` service as the public-facing service on port `12001` +6. Select the `frontend` service as the public-facing service on port `12016` 7. Click **Create Resource** ### Step 2: Configure Environment Variables @@ -72,15 +72,15 @@ Add these in Coolify before first deploy: | `APP_NAME` | `backend` | `AI Allucanget` | | `CORS_ORIGINS` | `backend` | `https://ai.allucanget.biz` | | `FLASK_SECRET_KEY` | `frontend` | `openssl rand -hex 32` | -| `BACKEND_URL` | `frontend` | `http://backend:12000` | +| `BACKEND_URL` | `frontend` | `http://backend:12015` | ### Step 3: Configure Domain and Proxy -1. Attach domain `ai.allucanget.biz` to the `frontend` service on port `12001` +1. Attach domain `ai.allucanget.biz` to the `frontend` service on port `12016` 2. Enable **Auto HTTPS** in Coolify -3. Coolify terminates TLS and forwards traffic directly to `frontend:12001` +3. Coolify terminates TLS and forwards traffic directly to `frontend:12016` -No nginx service is needed in the Coolify stack. The frontend Flask app proxies `/api/*` calls to `http://backend:12000` internally. Coolify's own reverse proxy handles external TLS termination. +No nginx service is needed in the Coolify stack. The frontend Flask app proxies `/api/*` calls to `http://backend:12015` internally. Coolify's own reverse proxy handles external TLS termination. ### Step 4: Persistent Storage @@ -103,11 +103,11 @@ No nginx service is needed in the Coolify stack. The frontend Flask app proxies 4. Choose the `main` branch 5. Set **Build Pack** to `nixpacks` 6. **CRITICAL: Set Base Directory to `/backend`** — this tells Nixpacks to look in the `backend/` subdirectory for `requirements.txt` and the Python application -7. Set **Ports Exposed** to `12000` +7. Set **Ports Exposed** to `12015` 8. Set **Start Command** to: ```txt - uvicorn app.main:app --host 0.0.0.0 --port 12000 + uvicorn app.main:app --host 0.0.0.0 --port 12015 ``` 9. Click **Create Resource** @@ -133,11 +133,11 @@ Add these as **Runtime** environment variables in Coolify: 3. Choose the `main` branch 4. Set **Build Pack** to `nixpacks` 5. **CRITICAL: Set Base Directory to `/frontend`** — this tells Nixpacks to look in the `frontend/` subdirectory for `requirements.txt` and the Python application -6. Set **Ports Exposed** to `12001` +6. Set **Ports Exposed** to `12016` 7. Set **Start Command** to: ```txt - gunicorn app.main:app --bind 0.0.0.0:12001 --workers 2 --timeout 120 + gunicorn app.main:app --bind 0.0.0.0:12016 --workers 2 --timeout 120 ``` 8. Click **Create Resource** @@ -152,7 +152,7 @@ Add these as **Runtime** environment variables in Coolify: | Variable | Description | Example | | ------------------ | ----------------------------------------- | --------------------------------------------------------------- | | `FLASK_SECRET_KEY` | Flask session cookie signing key | Generate with `openssl rand -hex 32` | -| `BACKEND_URL` | Internal URL to reach the backend service | `http://localhost:12000` (or use Coolify's internal networking) | +| `BACKEND_URL` | Internal URL to reach the backend service | `http://localhost:12015` (or use Coolify's internal networking) | ## Step 3: Configure Reverse Proxy @@ -161,13 +161,13 @@ Coolify provides a built-in reverse proxy. Configure routing rules: ### Backend Proxy Rules - **Domain**: `api.ai.allucanget.biz` (or subdomain of your choice) -- **Port**: `12000` +- **Port**: `12015` - **Path**: `/api/*` → forward to backend ### Frontend Proxy Rules - **Domain**: `ai.allucanget.biz` -- **Port**: `12001` +- **Port**: `12016` - **Path**: `/` → forward to frontend ### Nginx Configuration (Optional) @@ -180,7 +180,7 @@ If you need custom Nginx configuration, create `nginx/coolify.conf`: # Backend API proxy location /api/ { - proxy_pass http://backend:12000; + proxy_pass http://backend:12015; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -189,7 +189,7 @@ location /api/ { # Frontend proxy location / { - proxy_pass http://frontend:12001; + proxy_pass http://frontend:12016; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -222,7 +222,7 @@ If you want to persist DuckDB data: ### Docker Compose deployment fails in Coolify - Verify Coolify uses `docker-compose.coolify.yml`, not local `docker-compose.yml` -- Verify public domain points to `frontend` service on port `12001` +- Verify public domain points to `frontend` service on port `12016` - Do not add `nginx` to the Coolify stack — bind-mounting a local config file will fail since the file doesn't exist on the Coolify server ### Backend healthcheck stays unhealthy @@ -240,7 +240,7 @@ If you want to persist DuckDB data: ### Frontend can't reach backend - Ensure `BACKEND_URL` points to the correct internal URL -- If both services are on the same Coolify server, use `http://localhost:12000` +- If both services are on the same Coolify server, use `http://localhost:12015` - Check that the backend service is running and healthy ### CORS errors @@ -272,7 +272,7 @@ All required environment variables: - [ ] Repository pushed to Git - [ ] For Docker Compose: Coolify resource uses `docker-compose.coolify.yml` -- [ ] For Docker Compose: domain points to `frontend` service on port `12001` +- [ ] For Docker Compose: domain points to `frontend` service on port `12016` - [ ] Backend service created with correct base directory (`/backend`) - [ ] Backend environment variables configured - [ ] Frontend service created with correct base directory (`/frontend`) diff --git a/docs/deployment/docker-compose.md b/docs/deployment/docker-compose.md index 6e41bf4..6f77af2 100644 --- a/docs/deployment/docker-compose.md +++ b/docs/deployment/docker-compose.md @@ -44,9 +44,9 @@ docker compose up --build ``` 4. **Access the application**: - - Frontend UI: http://localhost:12001 - - Backend API: http://localhost:12000 - - API Health: http://localhost:12000/health + - Frontend UI: http://localhost:12016 + - Backend API: http://localhost:12015 + - API Health: http://localhost:12015/health - Nginx Proxy: http://localhost:80 (routes to frontend) or http://localhost:80/api (routes to backend) 5. **View logs**: @@ -77,8 +77,8 @@ The `.env` file in the project root is automatically loaded by Docker Compose. R | `OPENROUTER_API_KEY` | API key for AI generation | `sk-or-v1-...` | | `JWT_SECRET` | Secret for JWT token signing | (random hex string) | | `FLASK_SECRET_KEY` | Secret for Flask session cookies | (random hex string) | -| `BACKEND_URL` | Internal URL for frontend to reach backend | `http://backend:12000` (Docker) or `http://localhost:12000` (local dev) | -| `CORS_ORIGINS` | Allowed CORS origins for backend | `http://localhost:12001` (local) or `https://ai.allucanget.biz` (production) | +| `BACKEND_URL` | Internal URL for frontend to reach backend | `http://backend:12015` (Docker) or `http://localhost:12015` (local dev) | +| `CORS_ORIGINS` | Allowed CORS origins for backend | `http://localhost:12016` (local) or `https://ai.allucanget.biz` (production) | | `APP_URL` | Public URL of the backend | `http://localhost` or `https://ai.allucanget.biz` | | `APP_NAME` | Application name | `AI Allucanget` | @@ -97,7 +97,7 @@ The `docker-compose.yml` defines the following volume: │ │ │ ┌──────────────────┐ ┌──────────────────────────┐ │ │ │ Frontend │ │ Backend │ │ -│ │ Port 12001 │ │ Port 12000 │ │ +│ │ Port 12016 │ │ Port 12015 │ │ │ │ Flask + Gunicorn│◄──►│ FastAPI + Uvicorn │ │ │ │ (Service name: │ │ (Service name: backend) │ │ │ │ frontend) │ │ │ │ @@ -128,8 +128,8 @@ Output example: ``` NAME COMMAND SERVICE STATUS PORTS -ai-backend "uvicorn app.main:a…" backend Up 2m 0.0.0.0:12000->12000/tcp -ai-frontend "gunicorn app.main:…" frontend Up 2m 0.0.0.0:12001->12001/tcp +ai-backend "uvicorn app.main:a…" backend Up 2m 0.0.0.0:12015->12015/tcp +ai-frontend "gunicorn app.main:…" frontend Up 2m 0.0.0.0:12016->12016/tcp ai-nginx "nginx -g daemon of…" nginx Up 2m 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp ``` @@ -191,7 +191,7 @@ docker compose down --rmi all **Solution**: Start Docker Desktop (Windows/Mac) or start the Docker daemon (Linux). -### "Port 12000 or 12001 already in use" +### "Port 12015 or 12016 already in use" **Error**: `Error response from daemon: bind: address already in use` @@ -199,8 +199,8 @@ docker compose down --rmi all ```yaml ports: - - "13000:12000" # Maps host:13000 to container:12000 - - "13001:12001" # Maps host:13001 to container:12001 + - "13000:12015" # Maps host:13000 to container:12015 + - "13001:12016" # Maps host:13001 to container:12016 ``` ### Frontend cannot reach backend @@ -210,7 +210,7 @@ ports: **Ensure**: 1. Backend service is running: `docker compose ps` -2. `BACKEND_URL` in `.env` is set to `http://backend:12000` (not `localhost`) +2. `BACKEND_URL` in `.env` is set to `http://backend:12015` (not `localhost`) 3. Services are on the same Docker network: `docker compose ps` shows them in the same `docker-compose.yml` ### Database file not persisting diff --git a/frontend/Dockerfile b/frontend/Dockerfile index dca9983..4278285 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -15,7 +15,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Expose port -EXPOSE 12001 +EXPOSE 12016 # Run the application -CMD ["gunicorn", "app.main:app", "--bind", "0.0.0.0:12001", "--workers", "2", "--timeout", "120"] +CMD ["gunicorn", "app.main:app", "--bind", "0.0.0.0:12016", "--workers", "2", "--timeout", "120"] diff --git a/frontend/app/config.py b/frontend/app/config.py index 88f22a9..b9b3417 100644 --- a/frontend/app/config.py +++ b/frontend/app/config.py @@ -3,7 +3,8 @@ import os class Config: - SECRET_KEY = os.getenv("FLASK_SECRET_KEY", "dev-secret-change-in-production") - BACKEND_URL = os.getenv("BACKEND_URL", "http://localhost:12000") + SECRET_KEY = os.getenv( + "FLASK_SECRET_KEY", "dev-secret-change-in-production") + BACKEND_URL = os.getenv("BACKEND_URL", "http://localhost:12015") SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SAMESITE = "Lax" diff --git a/frontend/app/static/app.js b/frontend/app/static/app.js index c23bcb3..25d517d 100644 --- a/frontend/app/static/app.js +++ b/frontend/app/static/app.js @@ -79,6 +79,6 @@ document.addEventListener("DOMContentLoaded", () => { } catch (e) { console.error("Video polling error:", e); } - }, 12001); + }, 12016); } }); diff --git a/nginx/coolify.conf b/nginx/coolify.conf index 41eb7db..3ec2eeb 100644 --- a/nginx/coolify.conf +++ b/nginx/coolify.conf @@ -3,12 +3,12 @@ # Backend API proxy upstream backend { - server 127.0.0.1:12000; + server 127.0.0.1:12015; } # Frontend proxy upstream frontend { - server 127.0.0.1:12001; + server 127.0.0.1:12016; } server { diff --git a/nginx/docker-compose.conf b/nginx/docker-compose.conf index fbc0a86..eef99ac 100644 --- a/nginx/docker-compose.conf +++ b/nginx/docker-compose.conf @@ -3,12 +3,12 @@ # Backend API proxy - use Docker service name instead of localhost upstream backend { - server backend:12000; + server backend:12015; } # Frontend proxy - use Docker service name instead of localhost upstream frontend { - server frontend:12001; + server frontend:12016; } server {