diff --git a/COOLIFY_QUICK_FIX.md b/COOLIFY_QUICK_FIX.md index 940ad98..30d8fb4 100644 --- a/COOLIFY_QUICK_FIX.md +++ b/COOLIFY_QUICK_FIX.md @@ -1,10 +1,24 @@ # ✅ Coolify Deployment - FIXED! -## What Was Wrong +## Issues Fixed + +### Issue 1: Port Already Allocated ✅ **Error:** `Bind for 0.0.0.0:8000 failed: port is already allocated` -**Cause:** Your `docker-compose.yml` used `ports:` which tries to bind to the host's ports. Coolify uses Traefik reverse proxy, so it doesn't need (and conflicts with) port bindings. +**Cause:** Your `docker-compose.yml` used `ports:` which tries to bind to the host's ports. Coolify's dashboard runs on port 8000, causing a conflict. + +**Fix:** Changed `ports:` to `expose:` - Coolify's Caddy reverse proxy handles routing + +### Issue 2: Module/File Not Found ✅ + +**Backend Error:** `ModuleNotFoundError: No module named 'app'` + +**Frontend Error:** `npm error enoent Could not read package.json` + +**Cause:** Development volume mounts (`./backend:/app`, `./frontend:/app`) override Dockerfile COPY commands. In Coolify, these paths don't exist. + +**Fix:** Removed bind mounts from docker-compose.yml - files now copied by Dockerfile ## What I Fixed @@ -15,21 +29,29 @@ backend: ports: - "8000:8000" # ❌ Binds to host, causes conflict + volumes: + - ./backend:/app # ❌ Overrides Dockerfile, causes ModuleNotFoundError frontend: ports: - "5173:5173" # ❌ Binds to host, causes conflict + volumes: + - ./frontend:/app # ❌ Overrides Dockerfile, causes package.json error + - /app/node_modules ``` **After:** ```yaml backend: expose: - - "8000" # ✅ Internal only, Coolify handles routing + - "8000" # ✅ Internal only, Caddy handles routing + volumes: + - sqlite_data:/app/data # ✅ Keep named volume for database frontend: expose: - - "5173" # ✅ Internal only, Coolify handles routing + - "5173" # ✅ Internal only, Caddy handles routing + # ✅ No volumes - files copied by Dockerfile ``` ## Files Created for Production Deployment diff --git a/COOLIFY_VOLUME_FIX.md b/COOLIFY_VOLUME_FIX.md new file mode 100644 index 0000000..0bb168c --- /dev/null +++ b/COOLIFY_VOLUME_FIX.md @@ -0,0 +1,193 @@ +# ✅ Coolify Volume Mount Error - FIXED! + +## The Problem + +After fixing the port binding issue, Coolify deployment had new errors: + +**Backend Error:** +``` +ModuleNotFoundError: No module named 'app' +``` + +**Frontend Error:** +``` +npm error code ENOENT +npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/app/package.json' +``` + +## Root Cause + +The `docker-compose.yml` had **development volume mounts** that override the Dockerfile COPY commands: + +```yaml +# ❌ BEFORE - Development setup with bind mounts +services: + backend: + volumes: + - ./backend:/app # This path doesn't exist in Coolify! + - sqlite_data:/app/data + + frontend: + volumes: + - ./frontend:/app # This path doesn't exist in Coolify! + - /app/node_modules +``` + +**Why this caused errors:** +- In local development, `./backend` and `./frontend` exist relative to docker-compose.yml +- In Coolify, these paths don't exist in the build context +- The bind mount creates an **empty `/app` directory**, overriding all files copied by Dockerfile +- Result: No Python modules, no package.json, total failure! + +## The Fix + +Removed bind mounts from `docker-compose.yml`: + +```yaml +# ✅ AFTER - Production-ready, Coolify compatible +services: + backend: + volumes: + - sqlite_data:/app/data # Keep only named volume for database + + frontend: + # No volumes needed - files copied by Dockerfile +``` + +**What changed:** +- **Backend**: Removed `- ./backend:/app` bind mount +- **Frontend**: Removed `- ./frontend:/app` and `- /app/node_modules` bind mounts +- **Kept**: Named volume `sqlite_data:/app/data` for persistent SQLite database + +## Deploy to Coolify + +### Step 1: Commit and Push + +```bash +git add docker-compose.yml +git commit -m "Fix Coolify deployment: remove volume bind mounts" +git push +``` + +### Step 2: Trigger Deployment in Coolify + +1. Go to your Coolify dashboard +2. Navigate to your H2H application +3. Click **"Redeploy"** or trigger a new deployment +4. Watch the build logs - should complete without errors now! + +### Step 3: Configure Environment Variables + +In Coolify UI, set these environment variables: + +```bash +# Required +JWT_SECRET=your-secure-random-32-character-secret-key-here + +# Optional - Coolify auto-configures URLs, but you can override: +VITE_API_URL=https://your-domain.com/api +VITE_WS_URL=wss://your-domain.com +``` + +### Step 4: Configure Caddy Routing + +**Backend Service:** +- Internal Port: `8000` +- Public: Yes (if you want direct API access) +- Path: `/api` (optional, for API routing) + +**Frontend Service:** +- Internal Port: `5173` +- Public: Yes +- Path: `/` (root path) + +## What Was Fixed + +| Issue | Before | After | +|-------|--------|-------| +| Port binding conflict | `ports: - "8000:8000"` | `expose: - "8000"` | +| Backend bind mount | `- ./backend:/app` | Removed ✅ | +| Frontend bind mount | `- ./frontend:/app` | Removed ✅ | +| Email validator | Missing | Added to requirements.txt ✅ | + +## Testing After Deployment + +Once deployed successfully: + +```bash +# Test backend health +curl https://your-domain.com/health + +# Test backend API docs +curl https://your-domain.com/docs + +# Test frontend (in browser) +https://your-domain.com +``` + +## Development vs Production + +### For Local Development (with hot-reload) + +If you want hot-reload for local development, create a separate `docker-compose.dev.yml`: + +```yaml +services: + backend: + build: ./backend + ports: + - "8000:8000" # Local development can use ports + volumes: + - ./backend:/app # Hot-reload for development + - sqlite_data:/app/data + command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload + + frontend: + build: ./frontend + ports: + - "5173:5173" # Local development can use ports + volumes: + - ./frontend:/app # Hot-reload for development + - /app/node_modules + command: npm run dev -- --host + depends_on: + - backend + +volumes: + sqlite_data: +``` + +**Usage:** +```bash +# Local development with hot-reload +docker compose -f docker-compose.dev.yml up + +# Production/Coolify deployment +docker compose up +``` + +### For Production Optimization (Optional) + +Consider using the production Dockerfile for frontend: + +**In Coolify UI:** +- Set "Dockerfile Path" for frontend to: `frontend/Dockerfile.prod` +- This uses Nginx instead of Vite dev server +- Serves optimized static build on port 80 +- Better performance and security + +## Summary + +✅ **Bind mount issue FIXED**: Removed development volume mounts from docker-compose.yml + +✅ **Coolify compatible**: Files now copied by Dockerfile, not overridden by volumes + +✅ **Both errors resolved**: +- Backend `ModuleNotFoundError` → Fixed (app module copied) +- Frontend `package.json not found` → Fixed (package.json copied) + +✅ **Ready to deploy**: Commit, push, and redeploy in Coolify! + +--- + +**The deployment should work now!** Both the port conflict and volume mount issues are resolved. 🎉 diff --git a/docker-compose.yml b/docker-compose.yml index dd0cd88..d0df210 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ services: - ACCESS_TOKEN_EXPIRE_MINUTES=30 - REFRESH_TOKEN_EXPIRE_DAYS=7 volumes: - - ./backend:/app - sqlite_data:/app/data command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload @@ -21,9 +20,6 @@ services: environment: - VITE_API_URL=http://localhost:8000 - VITE_WS_URL=ws://localhost:8000 - volumes: - - ./frontend:/app - - /app/node_modules command: npm run dev -- --host depends_on: - backend