feat(docker): install production dependencies only in the app images #251

Merged
ullrich merged 1 commit from prod-only-images into main 2026-10-11 19:12:03 +00:00
Owner

Closes #250.

The journal and planner runtime images now contain only production dependencies. A new prod-deps stage runs pnpm install --frozen-lockfile --prod, and the runtime stage copies node_modules from it.

Changes

  • Missing dependencies declared. The apps imported several packages that only the root package.json declared, as dev dependencies. The table in #250 lists them.
  • Dependencies of bundled workspace packages. Vite bundles @trails-cool/i18n and @trails-cool/gpx into the server build but leaves their own imports external. The apps therefore also declare i18next, i18next-browser-languagedetector and linkedom.
  • drizzle-kit is now a dependency of apps/journal, because the deploy runs drizzle-kit push inside the journal image. drizzle.config.ts now uses a type-only import, so it no longer resolves drizzle-kit from packages/db/.

Guards

  • Lint: import-x/no-extraneous-dependencies covers app and package source. Every import must be declared in the importing package. Against the old package.json files, it reports exactly the imports this PR declares.
  • Build: scripts/check-server-externals.mjs runs in the Docker build. It fails when the server bundle imports a package that does not resolve. Lint cannot find this kind of error. In the first test build, the journal then returned HTTP 500 for every page, while /api/health returned 200.

Tested locally

Both images were built for arm64, with a throwaway PostGIS container on its own Docker network.

  • npx --no drizzle-kit push --config /app/packages/db/drizzle.config.ts --force in the journal image applies the schema. --no means npx uses the installed copy and never downloads one.
  • migrate-data.ts in the journal image exits with 0.
  • journal /api/health, / and /auth/login: all return 200. planner /health and /: both return 200. The logs contain no errors.
  • The build check passes (31 and 25 external imports). It fails when I delete a package inside a container.
  • pnpm lint, pnpm typecheck, pnpm test and scripts/check-dockerfiles.sh all pass. I did not run the e2e suite locally; CI runs it.

Size

journal 1.77 → 1.47 GB, planner 1.71 → 1.35 GB. These are approximate: the test images are arm64 and the registry images are amd64.

The images are still large, because about 70 React Native and Expo packages are installed as production dependencies. pnpm resolves drizzle-orm and react-i18next with peer dependencies from apps/mobile across the whole workspace. That is a follow-up (noted in #250).

Before merging

No auto-merge. A merge deploys new production images through cd-apps.yml. Check the staging preview first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LQv5c9rFGq2hSPpjLiFmQ8

Closes #250. The journal and planner runtime images now contain only production dependencies. A new `prod-deps` stage runs `pnpm install --frozen-lockfile --prod`, and the runtime stage copies `node_modules` from it. ## Changes - **Missing dependencies declared.** The apps imported several packages that only the root `package.json` declared, as dev dependencies. The table in #250 lists them. - **Dependencies of bundled workspace packages.** Vite bundles `@trails-cool/i18n` and `@trails-cool/gpx` into the server build but leaves their own imports external. The apps therefore also declare `i18next`, `i18next-browser-languagedetector` and `linkedom`. - **`drizzle-kit`** is now a dependency of `apps/journal`, because the deploy runs `drizzle-kit push` inside the journal image. `drizzle.config.ts` now uses a type-only import, so it no longer resolves `drizzle-kit` from `packages/db/`. ## Guards - **Lint:** `import-x/no-extraneous-dependencies` covers app and package source. Every import must be declared in the importing package. Against the old `package.json` files, it reports exactly the imports this PR declares. - **Build:** `scripts/check-server-externals.mjs` runs in the Docker build. It fails when the server bundle imports a package that does not resolve. Lint cannot find this kind of error. In the first test build, the journal then returned HTTP 500 for every page, while `/api/health` returned 200. ## Tested locally Both images were built for arm64, with a throwaway PostGIS container on its own Docker network. - `npx --no drizzle-kit push --config /app/packages/db/drizzle.config.ts --force` in the journal image applies the schema. `--no` means npx uses the installed copy and never downloads one. - `migrate-data.ts` in the journal image exits with 0. - journal `/api/health`, `/` and `/auth/login`: all return 200. planner `/health` and `/`: both return 200. The logs contain no errors. - The build check passes (31 and 25 external imports). It fails when I delete a package inside a container. - `pnpm lint`, `pnpm typecheck`, `pnpm test` and `scripts/check-dockerfiles.sh` all pass. I did not run the e2e suite locally; CI runs it. ## Size journal 1.77 → 1.47 GB, planner 1.71 → 1.35 GB. These are approximate: the test images are arm64 and the registry images are amd64. The images are still large, because about 70 React Native and Expo packages are installed as production dependencies. pnpm resolves `drizzle-orm` and `react-i18next` with peer dependencies from `apps/mobile` across the whole workspace. That is a follow-up (noted in #250). ## Before merging **No auto-merge.** A merge deploys new production images through `cd-apps.yml`. Check the staging preview first. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LQv5c9rFGq2hSPpjLiFmQ8
feat(docker): install production dependencies only in the app images
All checks were successful
CD Staging / Build & Push journal Image (pull_request) Has been skipped
CD Staging / Build & Push planner Image (pull_request) Has been skipped
CD Staging / Deploy Staging (pull_request) Has been skipped
CD Staging / Deploy PR Preview (pull_request) Has been skipped
CI / Dockerfile Package Check (pull_request) Successful in 6s
CI / Security Scan (pull_request) Successful in 8s
CI / Visual Tests (pull_request) Successful in 49s
CI / Checks (pull_request) Successful in 2m26s
CI / Journal Image Smoke Test (pull_request) Successful in 2m52s
CI / E2E Tests (pull_request) Successful in 3m21s
Cancel superseded CI / Cancel in-flight CI (pull_request) Successful in 3s
CD Staging / Tear Down PR Preview (pull_request) Successful in 14s
9026b9943d
The journal and planner runtime images installed all dependencies,
including build tooling. They now copy node_modules from a new
`prod-deps` stage (`pnpm install --frozen-lockfile --prod`).

This needed every runtime import declared where it is used. Several
resolved only through the root devDependencies (postgres, react-i18next,
fit-file-parser, leaflet, ...). Two guards keep it that way:

- ESLint `import-x/no-extraneous-dependencies` on app and package
  source: an import must be declared in the importing package.
- scripts/check-server-externals.mjs runs in the Docker build and fails
  when the React Router server bundle imports a package that does not
  resolve. Vite bundles workspace packages but leaves their dependencies
  external, so the app must declare them too (i18next, linkedom, ...).
  Lint cannot see this; without it every page render returns 500 while
  /health still answers 200.

drizzle-kit becomes a journal dependency, because the deploy runs
`drizzle-kit push` inside the journal image. drizzle.config.ts now uses
a type-only import, so it no longer resolves drizzle-kit from
packages/db.

Closes #250

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LQv5c9rFGq2hSPpjLiFmQ8
ullrich deleted branch prod-only-images 2026-10-11 19:12:04 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
trails-cool/trails!251
No description provided.