Files
filezzy-staging/backend/Dockerfile.prod
2026-02-04 20:10:28 +01:00

46 lines
1.6 KiB
Docker

# =============================================================================
# Backend (API Gateway) - Production build for staging/production
# =============================================================================
# Multi-stage: build with tsc, run pre-compiled. Avoids ts-node-dev and OOM.
# =============================================================================
FROM node:20-alpine AS builder
WORKDIR /app
# Increase Node heap for tsc (avoids OOM in container)
ENV NODE_OPTIONS=--max-old-space-size=1024
COPY package*.json ./
RUN npm install
COPY . .
RUN npx prisma generate
RUN npm run build
# Production runner
FROM node:20-alpine AS runner
# OpenSSL required for Prisma engine (db push, db seed, runtime); tini for clean init
RUN apk add --no-cache openssl tini
WORKDIR /app
ENV NODE_ENV=production
# Use Prisma OpenSSL 3 engine on Alpine (schema has binaryTargets linux-musl-openssl-3.0.x)
ENV PRISMA_QUERY_ENGINE_LIBRARY=/app/node_modules/.prisma/client/libquery_engine-linux-musl-openssl-3.0.x.so.node
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
# scripts + src needed so prisma-init can run: npx prisma db seed (seed.ts imports scripts/seed-app-config → src/config)
COPY --from=builder /app/scripts ./scripts
COPY --from=builder /app/src ./src
# Env at runtime from compose env_file (../.env.staging); .env is in .dockerignore so not in image
EXPOSE 4000
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "dist/index.js"]