|
| 1 | +# 🔧 Deployment Fix - Azure 504 Gateway Timeout Issue |
| 2 | + |
| 3 | +**Date**: October 2, 2025 |
| 4 | +**Issue**: https://app-scripting-editor.trackmangolfdev.com/ returns 504 Gateway Timeout |
| 5 | +**Status**: ✅ FIXED - Changes ready to commit and push |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 🐛 Root Cause Analysis |
| 10 | + |
| 11 | +### Problem 1: **Wrong Dockerfile Used** |
| 12 | +- GitHub Actions was building with `./Dockerfile` (nginx-only frontend) |
| 13 | +- Should build with `./server/Dockerfile` (Express API + frontend) |
| 14 | +- **Result**: Azure deployed an nginx container without the Express API |
| 15 | + |
| 16 | +### Problem 2: **Missing Image Build Order** |
| 17 | +- The API Dockerfile depends on `app-scripting-editor:latest` being already built |
| 18 | +- Workflow only built one image, causing build failures or stale image usage |
| 19 | +- **Result**: API image couldn't find frontend assets or used outdated ones |
| 20 | + |
| 21 | +### Problem 3: **Build Context Path Issues** |
| 22 | +- Server Dockerfile had incorrect paths: `COPY server/ ./server` then `WORKDIR /srv/server` |
| 23 | +- This created nested directories and broke the build |
| 24 | +- **Result**: `npm run build` would fail or produce incorrect output |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## ✅ Changes Made |
| 29 | + |
| 30 | +### 1. **Fixed `.github/workflows/docker-build.yml`** |
| 31 | + |
| 32 | +**Before**: |
| 33 | +```yaml |
| 34 | +- name: Build & push API image |
| 35 | + with: |
| 36 | + file: ./Dockerfile # ❌ Wrong file! |
| 37 | +``` |
| 38 | +
|
| 39 | +**After**: |
| 40 | +```yaml |
| 41 | +# Step 1: Build frontend image first |
| 42 | +- name: Build & push Editor image (Frontend/nginx) |
| 43 | + with: |
| 44 | + file: ./Dockerfile |
| 45 | + tags: app-scripting-editor:latest |
| 46 | + |
| 47 | +# Step 2: Build API image (depends on editor image) |
| 48 | +- name: Build & push API image (Node/Express + SPA) |
| 49 | + with: |
| 50 | + file: ./server/Dockerfile # ✅ Correct file! |
| 51 | + tags: app-scripting-editor-api:latest |
| 52 | +``` |
| 53 | +
|
| 54 | +**Changes**: |
| 55 | +- ✅ Added two-stage build: frontend first, then API |
| 56 | +- ✅ Builds in correct order with proper dependencies |
| 57 | +- ✅ Both images tagged and pushed to ACR |
| 58 | +
|
| 59 | +### 2. **Fixed `server/Dockerfile`** |
| 60 | + |
| 61 | +**Before**: |
| 62 | +```dockerfile |
| 63 | +COPY server/ ./server |
| 64 | +WORKDIR /srv/server # ❌ Creates nested path |
| 65 | +RUN npm run build |
| 66 | +``` |
| 67 | + |
| 68 | +**After**: |
| 69 | +```dockerfile |
| 70 | +COPY server/ ./ # ✅ Copy to current directory |
| 71 | +RUN npm run build |
| 72 | +``` |
| 73 | + |
| 74 | +**Changes**: |
| 75 | +- ✅ Fixed build context paths to avoid nested directories |
| 76 | +- ✅ Added default value for REGISTRY arg |
| 77 | +- ✅ Fixed package.json copy in final stage |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## 🚀 Deployment Steps |
| 82 | + |
| 83 | +### **To Fix Immediately:** |
| 84 | + |
| 85 | +1. **Commit and push the changes**: |
| 86 | + ```bash |
| 87 | + git add .github/workflows/docker-build.yml server/Dockerfile |
| 88 | + git commit -m "fix: correct Docker build workflow and API image configuration" |
| 89 | + git push origin main |
| 90 | + ``` |
| 91 | + |
| 92 | +2. **GitHub Actions will automatically**: |
| 93 | + - Build the frontend image (`app-scripting-editor:latest`) |
| 94 | + - Build the API image (`app-scripting-editor-api:latest`) |
| 95 | + - Deploy the API image to Azure App Service |
| 96 | + - Restart the app |
| 97 | + - Health check `/api/health` |
| 98 | + |
| 99 | +3. **Monitor the deployment**: |
| 100 | + - GitHub Actions: https://github.com/TrackMan/tps-app-scripting/actions |
| 101 | + - Wait for both workflows to complete (5-10 minutes) |
| 102 | + |
| 103 | +4. **Verify the fix**: |
| 104 | + ```bash |
| 105 | + # Should return: {"status":"ok","uptime":...} |
| 106 | + curl https://app-scripting-editor.trackmangolfdev.com/api/health |
| 107 | + |
| 108 | + # Should load the frontend |
| 109 | + curl https://app-scripting-editor.trackmangolfdev.com/ |
| 110 | + ``` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 📊 Expected Results |
| 115 | + |
| 116 | +After deployment: |
| 117 | +- ✅ `/api/health` returns `200 OK` with `{"status":"ok"}` |
| 118 | +- ✅ `/` loads the React frontend |
| 119 | +- ✅ Frontend can call backend APIs |
| 120 | +- ✅ No more 504 Gateway Timeout errors |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## 🔍 How to Verify in Azure |
| 125 | + |
| 126 | +### Check Azure App Service Logs: |
| 127 | +```bash |
| 128 | +# Stream logs |
| 129 | +az webapp log tail \ |
| 130 | + --name tps-app-scripting-editor \ |
| 131 | + --resource-group tps-app-scripting-rg |
| 132 | +
|
| 133 | +# Should see: |
| 134 | +# "Server running on http://localhost:4000" |
| 135 | +# "Static frontend directory found at /app/editor-dist" |
| 136 | +``` |
| 137 | + |
| 138 | +### Check Container Configuration: |
| 139 | +```bash |
| 140 | +# Verify correct image is deployed |
| 141 | +az webapp config container show \ |
| 142 | + --name tps-app-scripting-editor \ |
| 143 | + --resource-group tps-app-scripting-rg |
| 144 | +
|
| 145 | +# Should show: |
| 146 | +# "docker-custom-image-name": "tpsappscriptingacr.azurecr.io/app-scripting-editor-api:latest" |
| 147 | +``` |
| 148 | + |
| 149 | +### Check App Settings: |
| 150 | +```bash |
| 151 | +# Verify port is set correctly |
| 152 | +az webapp config appsettings list \ |
| 153 | + --name tps-app-scripting-editor \ |
| 154 | + --resource-group tps-app-scripting-rg \ |
| 155 | + --query "[?name=='WEBSITES_PORT'].value" -o tsv |
| 156 | +
|
| 157 | +# Should return: 4000 |
| 158 | +``` |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## 🛡️ Prevention |
| 163 | + |
| 164 | +To prevent this issue in the future: |
| 165 | + |
| 166 | +1. **Add build validation**: Test both Dockerfiles locally before pushing |
| 167 | +2. **Add health check monitoring**: Set up Azure Monitor alerts for failed health checks |
| 168 | +3. **Document image dependencies**: Clearly note that API image depends on editor image |
| 169 | +4. **Add image smoke tests**: Verify both `/api/health` and frontend load in CI |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## 📝 Additional Notes |
| 174 | + |
| 175 | +### Image Architecture: |
| 176 | +- **app-scripting-editor**: Standalone nginx image with React frontend (for testing) |
| 177 | +- **app-scripting-editor-api**: Node.js Express server + React frontend (for production) |
| 178 | + |
| 179 | +### Why Two Images? |
| 180 | +- Editor image: Fast frontend-only testing and development |
| 181 | +- API image: Complete production deployment with backend + frontend |
| 182 | + |
| 183 | +### Port Configuration: |
| 184 | +- Express server listens on port **4000** |
| 185 | +- Azure App Service `WEBSITES_PORT=4000` routes traffic correctly |
| 186 | +- No nginx needed in API image (Express serves static files) |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +## ✅ Checklist |
| 191 | + |
| 192 | +- [x] Fixed `.github/workflows/docker-build.yml` to build both images in order |
| 193 | +- [x] Fixed `server/Dockerfile` build context paths |
| 194 | +- [x] Documented the issue and solution |
| 195 | +- [ ] Commit changes to git |
| 196 | +- [ ] Push to trigger deployment |
| 197 | +- [ ] Monitor GitHub Actions |
| 198 | +- [ ] Verify `/api/health` endpoint |
| 199 | +- [ ] Verify frontend loads |
| 200 | +- [ ] Update team on resolution |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +**Status**: Ready to deploy! Push the changes to fix the issue. 🚀 |
0 commit comments