fix(smtp): install the SMTP server from the monorepo lockfile in every build

Merged
KM
8d ago
+132-337

The SMTP server's dependencies were never installed from our lockfile, in production or in the self-host image. This makes every build install exactly the locked versions.

The problem

  • apps/smtp-server/pnpm-workspace.yaml made the SMTP app its own pnpm workspace. So pnpm installed it without the root pnpm-lock.yaml and resolved fresh versions on every build.
  • Production (Coolify) had a second, unlocked apps/smtp-server/node_modules that the server actually loads: smtp-server 3.21.4, nodemailer 10.5.0, mailparser 3.14.3. The lockfile said 3.21.1, 10.2.1 and 3.12.4.
  • The self-host smtp-proxy image was built with context: ./apps/smtp-server, where there's no lockfile, so its pnpm install was unlocked too.

What changed

  • Removed apps/smtp-server/pnpm-workspace.yaml. Its settings (allowBuilds: esbuild, the linkify-it override) are already in the root workspace file.
  • The lockfile and package.json now pin smtp-server 3.21.4, nodemailer 10.5.0 and mailparser 3.14.3, the versions production runs today, so live behaviour doesn't change.
    • Only those packages and their deps (libmime, @zone-eu/mailsplit, encoding-japanese) change version. I diffed every name@version in the lockfile's packages section.
    • The other lockfile churn is pnpm re-normalising optional-peer suffixes (e.g. next@15.5.29 no longer lists the optional @babel/core peer). No versions change, and the web app has no Babel config (SWC).
  • apps/smtp-server/Dockerfile now builds from the repository root:
    • pnpm install --frozen-lockfile --filter smtp-server, then build.
    • Then a --prod frozen reinstall, so the image carries only runtime deps (no typescript/tsup/vitest).
    • The builder copies only src, tsconfig.json and tsup.config.ts, never local .env files or node_modules.
    • The image mirrors the repo layout and still runs from /app (CMD node apps/smtp-server/dist/server.js), so a mounted /app/.env keeps loading. Same ports and env vars.
  • publish.yml: the smtp-proxy build context is now ..
  • .dockerignore now applies at any depth (**/node_modules, **/.next/, **/.turbo, **/.env, **/.env.*, keeping **/.env*.example). With a whole-repo build context, a developer's nested .env or node_modules can no longer reach either image. Verified by planting both and listing the build context.

Verified locally (re-run after the review fixes: SMTP image amd64, 4-port end-to-end, web image build)

  • New image (amd64): Node 22.23.5, and versions match the lockfile exactly. No dev tools in the image (224 MB).
  • End-to-end: with test TLS certs and a fake useSend API, I sent mail with nodemailer through 465, 587, 2465 and 2587. All returned 250 OK, and the API received each email with the right auth, recipient and subject.
  • Coolify's current Nixpacks build (its exact install/build/start commands) still works, and now resolves the lockfile versions (3.21.4 / 10.5.0). So a Coolify redeploy before the switch is safe.
  • SMTP unit tests 20/20. Web: typecheck, unit 313, tRPC 23, API 44, plus pnpm build:editor && pnpm build:web.

Next

  1. Switch the Coolify SMTP app to this Dockerfile (base dir /, Dockerfile apps/smtp-server/Dockerfile), and narrow its disk mount.
  2. Then delete nixpacks.toml and docker/nixpacks/install-node.sh, which nothing will use any more.

Self-hosters get the reproducible image in the next release. The container still starts in /app.

Not changed here: the container still runs as root, as before. Switching to USER node would break reading the root-only Let's Encrypt keys, so it gets its own change.