Multi-stage Dockerfile (deps -> build -> prod-deps -> runtime) that ships a full production node_modules rather than Next's standalone output, since standalone tracing is incompatible with a custom server (noted back in M1). Runs as a non-root user with a read-only rootfs, dropped capabilities, and tini as PID 1. tsx moves from dev to a real runtime dependency since the production start script runs server.ts directly rather than a precompiled bundle. next.config.ts marks dockerode/systeminformation as serverExternalPackages so Next's bundler leaves their OS-conditional requires alone. docker-compose.yml mirrors the sibling stacks' own conventions (TRAEFIK_HOST/NETWORK_NAME in .env, falcon_network as an external network, the same traefik.* label shape) so it fits their existing tooling, plus a new /api/health route and healthcheck.mjs for the container HEALTHCHECK. Verified end-to-end with a real `docker build` + `docker compose up`: non-root/read-only/cap-dropped container boots cleanly, is reachable by container name from another container on the shared network (as Traefik would reach it), and the container's own HEALTHCHECK reports healthy. That run surfaced a real gap - the non-root user got EACCES on /var/run/docker.sock, since it's owned by root:docker on the host - fixed via group_add on a DOCKER_GID env var (documented in .env.example with the command to find it), then re-verified that both docker.sock access and label-based auto-discovery work correctly under the fix.
47 lines
1.3 KiB
Docker
47 lines
1.3 KiB
Docker
# output: 'standalone' can't be combined with a custom server (Next traces
|
|
# its own minimal server.js and ignores custom server files), so this image
|
|
# ships a full production node_modules instead of a standalone bundle.
|
|
|
|
FROM node:22-alpine AS base
|
|
RUN corepack enable
|
|
|
|
FROM base AS deps
|
|
WORKDIR /app
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
FROM base AS build
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
RUN pnpm build
|
|
|
|
FROM base AS prod-deps
|
|
WORKDIR /app
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN pnpm install --prod --frozen-lockfile
|
|
|
|
FROM node:22-alpine AS runtime
|
|
RUN apk add --no-cache tini
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
|
|
RUN addgroup -S pulsenode && adduser -S pulsenode -G pulsenode
|
|
|
|
COPY --from=prod-deps /app/node_modules ./node_modules
|
|
COPY --from=build /app/.next ./.next
|
|
COPY --from=build /app/public ./public
|
|
COPY package.json server.ts tsconfig.json next.config.ts healthcheck.mjs ./
|
|
COPY --from=build /app/lib ./lib
|
|
|
|
RUN mkdir -p /app/config && chown -R pulsenode:pulsenode /app
|
|
|
|
USER pulsenode
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
|
CMD ["node", "healthcheck.mjs"]
|
|
|
|
ENTRYPOINT ["tini", "--"]
|
|
CMD ["node_modules/.bin/tsx", "server.ts"]
|