Skip to content

Commit 1a02363

Browse files
committed
Fixes Docker build order, standardizes schema IDs, and refines event types
Ensures correct Dockerfiles are used for building and deployment, preventing Azure gateway timeouts. Unifies schema references for consistent versioning in project files. Enhances event definitions to streamline telemetry and debugging.
1 parent 54ba320 commit 1a02363

18 files changed

+752
-51
lines changed

DEPLOYMENT_FIX.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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. 🚀

docs/schema-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Schema Reference
22

3-
* **Canonical ID:** `https://schemas.trackman.com/app-scripting/1-0-0.json`
3+
* **Canonical ID:** `https://schemas.trackman.com/app-scripting/1.0.0.json`
44
* **Local path (versioned):** `schema/1.0.0/app-scripting.schema.json`
55
* **Stable entrypoint:** `schema/latest/app-scripting.schema.json` (pointer or copy)
66

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"scripts": {
66
"validate": "node tools/validate.js",
77
"format": "node tools/format.js",
8-
"editor": "npm run dev",
8+
"editor": "npm run dev",
99
"dev": "vite",
10+
"dev:server": "cd server && npm run dev",
11+
"start-dev": "concurrently \"npm run dev\" \"npm run dev:server\" --names \"frontend,backend\" --prefix-colors \"cyan,yellow\"",
1012
"build": "vite build",
1113
"preview": "vite preview",
1214
"test": "vitest",

public/docs/schema-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Schema Reference
22

3-
* **Canonical ID:** `https://schemas.trackman.com/app-scripting/1-0-0.json`
3+
* **Canonical ID:** `https://schemas.trackman.com/app-scripting/1.0.0.json`
44
* **Local path (versioned):** `schema/1.0.0/app-scripting.schema.json`
55
* **Stable entrypoint:** `schema/latest/app-scripting.schema.json` (pointer or copy)
66

schema/1.0.0/activity-performance-center.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://schemas.trackman.com/app-scripting/1-0-0/activity-performance-center.schema.json",
3+
"$id": "https://schemas.trackman.com/app-scripting/1.0.0/activity-performance-center.schema.json",
44
"title": "Performance Center Activity",
55
"$defs": {
66
"PerformanceCenterScriptedConditions": {

schema/1.0.0/activity-range-analysis.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://schemas.trackman.com/app-scripting/1-0-0/activity-range-analysis.schema.json",
3+
"$id": "https://schemas.trackman.com/app-scripting/1.0.0/activity-range-analysis.schema.json",
44
"title": "Range Analysis Activity",
55
"$defs": {
66
"RangeAnalysisScriptedConditions": {

schema/1.0.0/app-scripting.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://schemas.trackman.com/app-scripting/1-0-0/app-scripting.schema.json",
3+
"$id": "https://schemas.trackman.com/app-scripting/1.0.0/app-scripting.schema.json",
44
"title": "TrackMan App Scripting — Script",
55
"type": "object",
66
"additionalProperties": false,

schema/1.0.0/shared.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://schemas.trackman.com/app-scripting/1-0-0/shared.schema.json",
3+
"$id": "https://schemas.trackman.com/app-scripting/1.0.0/shared.schema.json",
44
"title": "TrackMan App Scripting — Shared",
55
"type": "object",
66
"$defs": {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"id": "37117a97-5405-4f30-a6d2-ff2433bbe8c9",
4+
"subject": "/facility/f5456fe9-5829-45ec-9721-2f6bf130e9c5/location/f5456fe9-5829-45ec-9721-2f6bf130e9c5/bay/e9acfb8b-6ddd-45ac-9d5b-f23e51b1fe2d",
5+
"data": {
6+
"EventModel": {
7+
"Id": "79fa6c45-f5d6-46fe-ae14-a079c3257157",
8+
"Status": "Active",
9+
"Timestamp": "2025-10-01T14:40:44.8535520+00:00",
10+
"Players": [
11+
{
12+
"Id": "b89a5979-903f-4530-b9dd-89eb973da46d",
13+
"Name": "Player 1",
14+
"IsGuest": true
15+
}
16+
],
17+
"Activity": {
18+
"Type": "TPS",
19+
"SubType": "ShotAnalysis",
20+
"Identifier": "ShotAnalysis_tps10",
21+
"Id": "a3cba333-7745-4afe-8df3-0c99104fa591",
22+
"Timestamp": "2025-10-01T14:40:49.0380014+00:00"
23+
},
24+
"Language": "en-US",
25+
"IsLocked": false
26+
},
27+
"Facility": {
28+
"Id": "f5456fe9-5829-45ec-9721-2f6bf130e9c5",
29+
"Name": "DSG Global Dev"
30+
},
31+
"Location": {
32+
"Id": "f5456fe9-5829-45ec-9721-2f6bf130e9c5",
33+
"Name": "DSG Global"
34+
},
35+
"Bay": {
36+
"Id": "e9acfb8b-6ddd-45ac-9d5b-f23e51b1fe2d",
37+
"Name": "JFE Office"
38+
},
39+
"Client": {
40+
"Name": "TrackMan Performance Studio",
41+
"Properties": {
42+
"Version": "10.2.119"
43+
}
44+
},
45+
"Device": {
46+
"Id": "1d1d211b-981e-4ff4-907c-fc22f776358c"
47+
},
48+
"Radar": {
49+
"Properties": {
50+
"Model": "TMA4A",
51+
"Serial": "17404099",
52+
"Firmware": "2.10.0"
53+
}
54+
},
55+
"User": {
56+
"Id": "dab917d3-9588-476d-aeb0-0b65e775d0bc",
57+
"Name": "Michael Bertelsen"
58+
},
59+
"CustomerSession": {
60+
"Id": "79fa6c45-f5d6-46fe-ae14-a079c3257157"
61+
},
62+
"ActivitySession": {
63+
"Id": "a3cba333-7745-4afe-8df3-0c99104fa591"
64+
}
65+
},
66+
"eventType": "TPS.SessionInfo",
67+
"dataVersion": "1.0",
68+
"metadataVersion": "1",
69+
"eventTime": "2025-10-01T14:41:01.3801015Z",
70+
"topic": "/subscriptions/09c4d679-8b43-4520-ad0a-c598267ed94c/resourceGroups/dr2-dev/providers/Microsoft.EventGrid/domains/dr-eventgrid-dev/topics/facility-f5456fe9-5829-45ec-9721-2f6bf130e9c5"
71+
}
72+
]

0 commit comments

Comments
 (0)