CognxSafeTrack commited on
Commit
0aedaaf
·
1 Parent(s): cc0891d

feat: unified Dockerfile for multi-service deployment

Browse files
Files changed (1) hide show
  1. Dockerfile +9 -10
Dockerfile CHANGED
@@ -6,16 +6,18 @@ WORKDIR /app
6
  ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
7
  ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
8
 
9
- # Install System dependencies: Chromium (for Puppeteer), OpenSSL (for Prisma), and CA certs
10
  RUN apt-get update && apt-get install -y \
11
  chromium \
12
  openssl \
13
  ca-certificates \
14
  curl \
 
 
15
  --no-install-recommends && \
16
  rm -rf /var/lib/apt/lists/*
17
 
18
- # Install pnpm (Pinned to v9 to avoid ERR_INVALID_THIS fetch bug on Node 20) and Typescript
19
  RUN npm install -g pnpm@9 typescript tsx
20
 
21
  # Copy ALL workspace files first for a proper pnpm install
@@ -30,7 +32,7 @@ RUN pnpm install
30
  # Generate Prisma Client
31
  RUN pnpm --filter @repo/database generate
32
 
33
- # Give Node more memory and force IPv4 DNS resolution (fixes ENOTFOUND in native fetch)
34
  ENV NODE_OPTIONS="--max-old-space-size=2048 --dns-result-order=ipv4first"
35
 
36
  # Build all packages and apps to ensure dist folders are populated
@@ -40,14 +42,11 @@ RUN pnpm -r build
40
  EXPOSE 7860
41
  ENV PORT=7860
42
 
43
- # Force Docker cache invalidation - bump date to trigger clean rebuild
44
- ENV REBUILD_DATE="2026-04-22-v16-cors-preflight-fix"
45
-
46
  # SAFETY: Default to skipping DB push to prevent schema drift.
47
- # Only Railway (api service) should push schema — it overrides SKIP_DB_PUSH=false in its variables.
48
- # HF Space (gateway) MUST NOT push — it would drop columns added by Railway migrations.
49
  ENV SKIP_DB_PUSH=true
50
 
51
- # Sync DB schema only if DATABASE_URL is present and NOT on a gateway-only light node
52
- CMD ["sh", "-c", "if [ -n \"$DATABASE_URL\" ] && [ \"$SKIP_DB_PUSH\" != \"true\" ]; then echo '[STARTUP] Syncing DB schema...'; pnpm --filter @repo/database db:push --accept-data-loss; else echo '[STARTUP] Skipping DB Push (SKIP_DB_PUSH=true or no DATABASE_URL)'; fi && tsx apps/api/src/index.ts"]
 
53
 
 
 
6
  ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
7
  ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
8
 
9
+ # Install System dependencies: Chromium (for Puppeteer), OpenSSL (for Prisma), CA certs, and Worker deps (ffmpeg, espeak)
10
  RUN apt-get update && apt-get install -y \
11
  chromium \
12
  openssl \
13
  ca-certificates \
14
  curl \
15
+ ffmpeg \
16
+ espeak-ng \
17
  --no-install-recommends && \
18
  rm -rf /var/lib/apt/lists/*
19
 
20
+ # Install pnpm and Typescript
21
  RUN npm install -g pnpm@9 typescript tsx
22
 
23
  # Copy ALL workspace files first for a proper pnpm install
 
32
  # Generate Prisma Client
33
  RUN pnpm --filter @repo/database generate
34
 
35
+ # Give Node more memory and force IPv4 DNS resolution
36
  ENV NODE_OPTIONS="--max-old-space-size=2048 --dns-result-order=ipv4first"
37
 
38
  # Build all packages and apps to ensure dist folders are populated
 
42
  EXPOSE 7860
43
  ENV PORT=7860
44
 
 
 
 
45
  # SAFETY: Default to skipping DB push to prevent schema drift.
 
 
46
  ENV SKIP_DB_PUSH=true
47
 
48
+ # Entrypoint: Dispatch based on SERVICE_NAME env var
49
+ # Default is 'api' for backward compatibility
50
+ ENV SERVICE_NAME=api
51
 
52
+ CMD ["sh", "-c", "if [ \"$SERVICE_NAME\" = \"worker\" ]; then echo '[STARTUP] Starting WhatsApp Worker...'; node apps/whatsapp-worker/dist/index.js; else if [ -n \"$DATABASE_URL\" ] && [ \"$SKIP_DB_PUSH\" != \"true\" ]; then echo '[STARTUP] Syncing DB schema...'; pnpm --filter @repo/database db:push --accept-data-loss; fi && echo '[STARTUP] Starting API Gateway...'; tsx apps/api/src/index.ts; fi"]