Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(compose): probe API readiness with curl, like the image does

Yudhi Armyndharise91b7ccde417
diff --git a/docker-compose.yml b/docker-compose.yml
index e4da223e8..e8ab4d51e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -410,13 +410,7 @@ services:
condition: service_healthy
required: false
healthcheck:
- test:
- [
- 'CMD',
- 'node',
- '-e',
- "require('http').get('http://localhost:2785/api/health/ready', (r) => process.exit(r.statusCode === 200 ? 0 : 1))",
- ]
+ test: ['CMD', 'curl', '-f', 'http://localhost:2785/api/health/ready']
interval: 30s
timeout: 10s
retries: 3
diff --git a/docs/10-devops-infrastructure.md b/docs/10-devops-infrastructure.md
index e6c696be9..b5db74732 100644
--- a/docs/10-devops-infrastructure.md
+++ b/docs/10-devops-infrastructure.md
@@ -39,90 +39,36 @@ flowchart TB
### Dockerfile
+The repo `Dockerfile` is the source of truth; this section quotes the directives that matter
+rather than a second full copy. It is a two-stage build on a digest-pinned `node:22-slim`:
+
```dockerfile
-# Dockerfile (multi-stage build)
-
-# Build stage
-FROM node:22-slim AS builder
-WORKDIR /app
-COPY package*.json ./
-RUN npm ci
-COPY . .
-RUN npm run build
-
-# Runtime stage
-FROM node:22-slim
-
-# Install Chrome dependencies (avoid Debian's chromium package due to SIGTRAP in non-root)
-RUN apt-get update && apt-get install -y \
- curl \
- fonts-ipafont-gothic \
- fonts-wqy-zenhei \
- fonts-thai-tlwg \
- fonts-kacst \
- fonts-freefont-ttf \
- libxss1 \
- libnss3 \
- libnspr4 \
- libatk-bridge2.0-0 \
- libatk1.0-0 \
- libcups2 \
- libdrm2 \
- libxkbcommon0 \
- libxcomposite1 \
- libxdamage1 \
- libxfixes3 \
- libxrandr2 \
- libgbm1 \
- libasound2 \
- --no-install-recommends \
- && rm -rf /var/lib/apt/lists/*
-
-# Set Puppeteer skip download (we install it dynamically later)
-ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
-
-# Create app directory
-WORKDIR /app
-
-# Copy package files & install production dependencies
-COPY package*.json ./
-RUN npm ci --only=production
-
-# NOTE: this example targets linux/amd64. The repo's image keeps Debian's chromium on arm64 by
-# choice (Chrome for Testing publishes linux-arm64 builds only from 153 on). For arm64, install
-# Debian's `chromium` package and point PUPPETEER_EXECUTABLE_PATH to /usr/bin/chromium — see the
-# repo's Dockerfile for the mixed multi-arch build.
-# Download Chrome for Testing via Puppeteer and point ENV to it
-RUN mkdir -p /opt/puppeteer && \
- PUPPETEER_CACHE_DIR=/opt/puppeteer ./node_modules/.bin/puppeteer browsers install '[email protected]' && \
- chrome_path=$(find /opt/puppeteer/chrome/linux*/chrome-linux64/chrome | head -n 1) && \
- test -n "$chrome_path" && \
- ln -s "$chrome_path" /usr/local/bin/puppeteer-chrome
-ENV PUPPETEER_EXECUTABLE_PATH=/usr/local/bin/puppeteer-chrome
-
-# Copy build output (the stage above is named "builder")
-COPY --from=builder /app/dist ./dist
-
-# Create the unprivileged user the entrypoint drops to. The real image deliberately has NO
-# `USER openwa` directive and no `chown -R openwa /app /opt/puppeteer`: a full /app chown walks
-# every production dependency (issue #1045: ~35 minutes on a small VPS), and the container itself
-# is the Chromium confinement boundary (cap_drop ALL, read_only rootfs). Instead the image starts
-# as root, the entrypoint chowns ONLY the writable ./data volume and then drops privileges via
-# `exec gosu openwa node dist/main.js` (no-new-privileges blocks any setuid path back up). The ids
-# are pinned so the image can also be started as openwa directly (`--user 997:997`, runAsUser 997).
-RUN groupadd -r -g 997 openwa && useradd -r -u 997 -g openwa openwa
-
-# Expose port
-EXPOSE 2785
-
-# Health check (global API prefix is 'api'; readiness probes both databases)
+# Builder stage. --include=dev is required: a platform that leaks NODE_ENV=production into the
+# build (Coolify does) would otherwise skip @nestjs/cli and fail with `nest: not found`.
+RUN PUPPETEER_SKIP_DOWNLOAD=true npm ci --include=dev
+RUN npm run build && npm run dashboard:ci -- --include=dev && npm run dashboard:build && rm -f dist/*.tsbuildinfo
+
+# Production stage: runtime dependencies only, without install scripts; the dependency patchers
+# run in the same RUN, and any one failing fails the build.
+RUN npm ci --omit=dev --ignore-scripts \
+ && node scripts/patch-wwebjs-201832.js \
+ # ... one `&& node scripts/patch-*.js \` line per patcher ...
+ && npm cache clean --force
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:2785/api/health/ready || exit 1
-# Start app through the privilege-dropping entrypoint
-CMD ["docker-entrypoint.sh", "node", "dist/main.js"]
+# dumb-init is PID 1; the entrypoint runs as root, fixes /app/data ownership, then drops to the
+# openwa user with gosu before it execs the command.
+ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
+CMD ["node", "dist/main"]
```
+The image deliberately has no `USER openwa` directive and no `chown -R` over `/app`: a full chown
+walks every production dependency (#1045), so the entrypoint re-owns only the writable data volume
+and then drops privileges. Chromium comes from Chrome for Testing on amd64 and from Debian's
+`chromium` package on arm64; see the `Dockerfile` for the multi-arch build.
+
### Docker Compose (Development)
The repo's own `docker-compose.dev.yml` is a single-container local smoke test that runs the
diff --git a/docs/12-troubleshooting-faq.md b/docs/12-troubleshooting-faq.md
index be5cfec9c..6511e9b8f 100644
--- a/docs/12-troubleshooting-faq.md
+++ b/docs/12-troubleshooting-faq.md
@@ -105,17 +105,18 @@ at evalTypeScript (node:internal/process/execution:256:22)
**Cause:** Node 22 routes `node -e` through its TypeScript evaluator which rejects arrow-function
syntax. Podman also splits quoted shell commands on whitespace, truncating the `-e` argument.
-**Fix:** Use `curl` for the healthcheck instead of `node -e`:
+**Fix:** Use `curl` for the healthcheck instead of `node -e`. The shipped image, `docker-compose.yml`
+and `docker-compose.dev.yml` already do; this applies to a healthcheck you wrote yourself:
```dockerfile
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
- CMD curl -f http://localhost:2785/api/health || exit 1
+ CMD curl -f http://localhost:2785/api/health/ready || exit 1
```
```yaml
-# docker-compose.dev.yml
+# docker-compose healthcheck
healthcheck:
- test: ['CMD', 'curl', '-f', 'http://localhost:2785/api/health']
+ test: ['CMD', 'curl', '-f', 'http://localhost:2785/api/health/ready']
```
Ensure `curl` is installed in the production stage:
diff --git a/src/common/docs-dockerfile.spec.ts b/src/common/docs-dockerfile.spec.ts
new file mode 100644
index 000000000..32bb2dcd8
--- /dev/null
+++ b/src/common/docs-dockerfile.spec.ts
@@ -0,0 +1,44 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+/**
+ * docs/10 once carried a hand-written full Dockerfile that drifted from the real one: a bare
+ * `npm ci` in the builder, `npm ci --only=production` without the patchers, and a CMD that no image
+ * built from it could start. The docs now quote an excerpt, and this keeps every quoted directive
+ * present in the real Dockerfile, so the excerpt cannot drift the same way.
+ */
+describe('docs/10 Dockerfile excerpt matches the Dockerfile', () => {
+ const read = (...parts: string[]): string => readFileSync(join(__dirname, '..', '..', ...parts), 'utf8');
+
+ /** Code lines of every ```dockerfile fence in the "### Dockerfile" section, comments dropped. */
+ const quotedDirectives = (): string[] => {
+ const doc = read('docs', '10-devops-infrastructure.md');
+ const start = doc.indexOf('### Dockerfile\n');
+ const section = doc.slice(start, doc.indexOf('\n### ', start + 1));
+ return [...section.matchAll(/```dockerfile\n([\s\S]*?)```/g)]
+ .flatMap(fence => fence[1].split('\n'))
+ .map(line => line.trim())
+ .filter(line => line !== '' && !line.startsWith('#'));
+ };
+
+ it('quotes only lines the Dockerfile actually contains', () => {
+ const quoted = quotedDirectives();
+ // Guard the parser: an excerpt that scanned to nothing would pass vacuously.
+ expect(quoted.length).toBeGreaterThan(5);
+ const dockerfile = new Set(
+ read('Dockerfile')
+ .split('\n')
+ .map(line => line.trim()),
+ );
+ expect(quoted.filter(line => !dockerfile.has(line))).toEqual([]);
+ });
+
+ it('never prescribes the stale install or health probe forms', () => {
+ for (const doc of ['10-devops-infrastructure.md', '12-troubleshooting-faq.md']) {
+ const text = read('docs', doc);
+ expect(text).not.toContain('npm ci --only=production');
+ // The probe targets readiness, as the image and both compose files do, not the bare /api/health.
+ expect(text).not.toMatch(/localhost:2785\/api\/health(?:'|"| \|\|)/);
+ }
+ });
+});
diff --git a/src/modules/docker/compose-parity.spec.ts b/src/modules/docker/compose-parity.spec.ts
index dd5e41813..c9af8bbc0 100644
--- a/src/modules/docker/compose-parity.spec.ts
+++ b/src/modules/docker/compose-parity.spec.ts
@@ -374,6 +374,19 @@ describe('DockerService managed specs ↔ docker-compose.yml parity', () => {
expect(api?.ports).toEqual([expect.stringMatching(/:\$\{API_PORT:-2785\}:2785$/)]);
});
+ it('openwa-api uses the same readiness healthcheck in both compose files and the image', () => {
+ const root = join(__dirname, '../../..');
+ const apiHealthcheck = (file: string): string[] | undefined => {
+ const parsed = yaml.load(readFileSync(join(root, file), 'utf8')) as ComposeFile;
+ return Object.values(parsed.services).find(service => service.container_name === 'openwa-api')?.healthcheck?.test;
+ };
+ const url = 'http://localhost:2785/api/health/ready';
+ expect(apiHealthcheck('docker-compose.yml')).toEqual(['CMD', 'curl', '-f', url]);
+ expect(apiHealthcheck('docker-compose.dev.yml')).toEqual(apiHealthcheck('docker-compose.yml'));
+ const dockerfile = readFileSync(join(root, 'Dockerfile'), 'utf8');
+ expect(dockerfile).toContain(`CMD curl -f ${url} || exit 1`);
+ });
+
it('redis: sets the noeviction maxmemory policy BullMQ requires, on both launch paths', async () => {
const cfg = await capture('redis');
// The parity assertion above only proves the two launch paths AGREE — dropping the flag from