CognxSafeTrack commited on
Commit
4aef0ac
Β·
1 Parent(s): dd63a2e

fix: use robust start.sh script for deployment

Browse files
Files changed (2) hide show
  1. apps/whatsapp-worker/Dockerfile +5 -4
  2. start.sh +30 -0
apps/whatsapp-worker/Dockerfile CHANGED
@@ -28,8 +28,9 @@ ENV NODE_OPTIONS="--dns-result-order=ipv4first"
28
  # Expose the API port (Railway uses PORT env var, default 3001)
29
  EXPOSE 3001
30
 
31
- # ─── Combined startup ─────────────────────────────────────────────────────────
32
- # db:push is best-effort β€” failure must NOT block the API or worker.
33
- # API (webhook + REST) and worker (BullMQ) start in parallel.
34
- CMD ["sh", "-c", "echo '[CMD] Starting Database Push...' && (pnpm --filter @repo/database db:push || echo '[CMD] db:push failed, continuing...'); echo '[CMD] Starting API Server...' && pnpm --filter api start & sleep 5 && echo '[CMD] Starting WhatsApp Worker...' && pnpm --filter whatsapp-worker start & wait"]
 
35
 
 
28
  # Expose the API port (Railway uses PORT env var, default 3001)
29
  EXPOSE 3001
30
 
31
+ # Make startup script executable
32
+ RUN chmod +x ./start.sh
33
+
34
+ # Start services using the robust script
35
+ CMD ["./start.sh"]
36
 
start.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ echo "πŸš€ Starting EdTech Platform..."
4
+
5
+ # 1. Sync Database (Non-blocking)
6
+ echo "[DB] Syncing database schema..."
7
+ pnpm --filter @repo/database db:push || echo "[DB] db:push failed, continuing anyway..."
8
+
9
+ # 2. Start API Server
10
+ echo "[API] Starting API Gateway on port ${PORT:-8080}..."
11
+ # Using direct path to avoid pnpm overhead and potential filter issues
12
+ npx tsx apps/api/src/index.ts &
13
+ API_PID=$!
14
+
15
+ # 3. Wait a bit for API to initialize
16
+ sleep 5
17
+
18
+ # 4. Start WhatsApp Worker
19
+ echo "[WORKER] Starting WhatsApp Worker on internal port 8081..."
20
+ npx tsx apps/whatsapp-worker/src/index.ts &
21
+ WORKER_PID=$!
22
+
23
+ echo "[SYSTEM] Both services are starting. Monitoring processes..."
24
+
25
+ # 5. Wait and handle exits
26
+ wait -n $API_PID $WORKER_PID
27
+
28
+ echo "[SYSTEM] One of the services exited. Shutting down..."
29
+ kill $API_PID $WORKER_PID 2>/dev/null
30
+ exit 1