40 lines
775 B
Docker
40 lines
775 B
Docker
FROM node:22-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copier les fichiers de configuration
|
|
COPY package*.json ./
|
|
COPY tsconfig*.json ./
|
|
COPY nest-cli.json ./
|
|
|
|
# Installer TOUTES les dépendances (dev + prod pour le build)
|
|
RUN npm install && npm cache clean --force
|
|
|
|
# Copier le code source
|
|
COPY src ./src
|
|
|
|
# Builder l'application
|
|
RUN npm run build
|
|
|
|
# Stage production
|
|
FROM node:22-alpine AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# Installer seulement les dépendances de production
|
|
COPY package*.json ./
|
|
RUN npm install --only=production && npm cache clean --force
|
|
|
|
# Copier le build depuis le stage builder
|
|
COPY --from=builder /app/dist ./dist
|
|
|
|
# Créer un utilisateur non-root
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nestjs -u 1001
|
|
|
|
USER nestjs
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", "dist/main"]
|