fix: robust pdfjs-dist worker resolution + Docker deployment#2
fix: robust pdfjs-dist worker resolution + Docker deployment#2Chocksy wants to merge 1 commit intozmeyer44:mainfrom
Conversation
|
@Chocksy is attempting to deploy a commit to the Zach's Projects Team on Vercel. A member of the Team first needs to authorize it. |
4828549 to
8a7e832
Compare
Greptile SummaryThis PR fixes PDF.js worker resolution in Docker/bundled environments using
Confidence Score: 4/5Not safe to merge as-is: the web container will fail to start due to missing standalone config, and a race condition exists between migrations and app startup. Two P1 defects block the primary deployment path — the standalone output misconfiguration makes the web Dockerfile non-functional, and the missing migrate dependency causes unpredictable startup failures. apps/web/next.config.ts (needs output: standalone) and docker-compose.prod.yml (web/worker depends_on migrate) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[docker compose up] --> B[postgres]
B -->|service_healthy| C[migrate]
B -->|service_healthy| D[web]
B -->|service_healthy| E[worker]
C -->|one-shot: runs db:migrate| F[migrations complete]
D -->|starts immediately after postgres| G[web app running]
E -->|starts immediately after postgres| H[worker running]
F -.->|race condition: may finish AFTER web/worker| G
F -.->|race condition: may finish AFTER web/worker| H
style F fill:#f9f,stroke:#f00
style G fill:#faa,stroke:#f00
style H fill:#faa,stroke:#f00
Reviews (1): Last reviewed commit: "fix: robust pdfjs-dist worker resolution..." | Re-trigger Greptile |
| COPY --from=base /app/apps/web/.next/standalone ./ | ||
| COPY --from=base /app/apps/web/.next/static ./apps/web/.next/static | ||
| COPY --from=base /app/apps/web/public ./apps/web/public | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV PORT=3000 | ||
| ENV HOSTNAME="0.0.0.0" | ||
|
|
||
| CMD ["node", "apps/web/server.js"] |
There was a problem hiding this comment.
output: 'standalone' not set in next.config.ts
The Dockerfile copies from .next/standalone and runs node apps/web/server.js, but apps/web/next.config.ts does not include output: 'standalone'. Without this option Next.js will not generate the standalone directory or the server.js entrypoint — the COPY --from=base /app/apps/web/.next/standalone ./ step copies nothing, and the container will crash on startup.
Add to apps/web/next.config.ts:
const nextConfig: NextConfig = {
output: 'standalone',
transpilePackages: [
'@openvitals/common',
// ...
],
};
| depends_on: | ||
| postgres: | ||
| condition: service_healthy |
There was a problem hiding this comment.
web and worker can start before migrations complete
Both services depend only on postgres:service_healthy, not on the one-shot migrate container finishing. If either starts while migrations are still running the application will hit an empty schema and crash. Add migrate: condition: service_completed_successfully to both depends_on blocks.
| depends_on: | |
| postgres: | |
| condition: service_healthy | |
| depends_on: | |
| postgres: | |
| condition: service_healthy | |
| migrate: | |
| condition: service_completed_successfully |
| RUN pnpm run build && \ | ||
| cp $(find /app/node_modules -path "*/pdfjs-dist/legacy/build/pdf.worker.mjs" | head -1) dist/pdf.worker.mjs |
There was a problem hiding this comment.
Copied worker file is never used
The cp $(find ...) step copies pdf.worker.mjs into dist/, but the production stage does not include that file, and pdf.ts resolves the worker path at runtime via createRequire pointing to node_modules/pdfjs-dist/ — not dist/. This copy is a no-op in the final image and can be removed.
- Fix pdfjs-dist worker resolution using createRequire() instead of relative imports, which break in bundled/Docker environments - Add explicit worker options (useWorkerFetch, isEvalSupported, useSystemFonts) for reliable PDF parsing - Add web app Dockerfile with multi-stage build (alpine, standalone output) - Add ingestion-worker Dockerfile improvements - Add .dockerignore and docker-compose.prod.yml for self-hosted deployment
8a7e832 to
90d2646
Compare
Summary
createRequire()instead of relative imports that break in bundled/Docker environments. This replaces the less robust fix in 3356286..dockerignore, anddocker-compose.prod.ymlfor self-hosted deployment.Changes
services/ingestion-worker/src/lib/pdf.ts— UsecreateRequireto resolve worker path reliably + explicit pdfjs optionsapps/web/Dockerfile— Multi-stage Node 20 Alpine build with standalone outputservices/ingestion-worker/Dockerfile— Improved build.dockerignore— Standard exclusionsdocker-compose.prod.yml— Production compose with web, worker, postgres, redisTest plan
docker compose -f docker-compose.prod.yml upstarts all services