# https://www.tomray.dev/nestjs-docker-production#conclusion FROM node:22-alpine AS base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable WORKDIR /usr/src/app COPY --chown=app:nodejs package*.json ./ COPY --chown=app:nodejs pnpm-lock.yaml ./ FROM base AS prod-deps RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile FROM base AS build RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile COPY --chown=app:nodejs src ./src COPY --chown=app:nodejs tsconfig.json drizzle.config.ts . RUN pnpm run build FROM base RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 app COPY --chown=app:nodejs package*.json ./ COPY --chown=app:nodejs pnpm-lock.yaml ./ COPY --chown=app:nodejs --from=build /usr/src/app/node_modules ./node_modules COPY --chown=app:nodejs --from=build /usr/src/app/dist ./dist COPY --chown=app:nodejs drizzle ./drizzle RUN chown app:nodejs /usr/src/app EXPOSE 8000 USER app RUN mkdir data ENTRYPOINT ["node", "dist/src/app.js"]