# --- STAGE 1: Build ---
FROM node:22-alpine AS builder
WORKDIR /app
# HIER KEIN NODE_ENV=production setzen! Wir brauchen devDependencies zum Bauen.
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# --- STAGE 2: Runtime ---
FROM node:22-alpine
WORKDIR /app

# HIER ist es richtig!
ENV NODE_ENV=production

COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/package*.json /app/

# Installiert nur "dependencies" (Nest core, TypeORM, Helmet, Sharp etc.)
# "devDependencies" (TypeScript, Jest, ESLint) werden weggelassen.
RUN npm ci --omit=dev

# WICHTIG: Pfad prüfen (siehe Punkt 2 unten)
CMD ["node", "dist/src/main.js"]