write-ups-challenges-2024-2025/photos/backend/Dockerfile
2024-11-25 22:32:02 +01:00

45 lines
1.0 KiB
Docker

# 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"]