caelum0x a8b365b051 fix(docker): keep pnpm workspace layout in the MX image
apps/smtp-server/node_modules contains symlinks into the root pnpm store;
copying only that directory left them dangling and the container crashed
with "Cannot find module 'smtp-server'".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 02:12:30 +03:00

49 lines
2.3 KiB
Docker

# Inbound MX server (apps/smtp-server with INBOUND_ENABLED=true).
#
# Separate from the main web Dockerfile to keep image sizes small and allow
# the MX container to be run independently on port 25.
FROM node:22-alpine3.20 AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME/bin:$PNPM_HOME:$PATH"
RUN corepack enable
# ─── Builder ──────────────────────────────────────────────────────────────────
FROM base AS builder
RUN apk add --no-cache libc6-compat && apk update
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
COPY ./apps/smtp-server ./apps/smtp-server
COPY ./packages ./packages
RUN pnpm add turbo@^2.5.2 -g
RUN pnpm turbo prune smtp-server --docker
# ─── Installer ────────────────────────────────────────────────────────────────
FROM base AS installer
RUN apk add --no-cache libc6-compat && apk update
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN --mount=type=cache,id=pnpm-mx,target=/pnpm/store pnpm install --frozen-lockfile
COPY --from=builder /app/out/full/ .
RUN pnpm turbo run build --filter=smtp-server...
# ─── Runner ───────────────────────────────────────────────────────────────────
FROM base AS runner
RUN apk add --no-cache tini
# pnpm's apps/smtp-server/node_modules holds symlinks into the root
# node_modules/.pnpm store, so keep the workspace layout: copying only the
# app's node_modules leaves dangling links ("Cannot find module 'smtp-server'").
WORKDIR /app
COPY --from=installer /app/node_modules ./node_modules
COPY --from=installer /app/packages ./packages
COPY --from=installer /app/apps/smtp-server/node_modules ./apps/smtp-server/node_modules
COPY --from=installer /app/apps/smtp-server/dist ./apps/smtp-server/dist
COPY --from=installer /app/apps/smtp-server/package.json ./apps/smtp-server/package.json
WORKDIR /app/apps/smtp-server
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "dist/server.js"]