api-portfolio/Dockerfile
Заид Омар Медхат | Zaid Omar Medhat 6a4acfd7a4
All checks were successful
Deploy Production / deploy (push) Successful in 1m18s
fix docker
2026-01-27 14:36:55 +05:00

73 lines
1.4 KiB
Docker

# ============================================
# Development Stage
# ============================================
FROM node:22-alpine AS development
WORKDIR /app
# Install dependencies for native modules
RUN apk add --no-cache python3 make g++
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies)
RUN npm ci
# Copy source code
COPY . .
# Expose port
EXPOSE 3000
# Start in development mode
CMD ["npm", "run", "start:dev"]
# ============================================
# Build Stage
# ============================================
FROM node:22-alpine AS build
WORKDIR /app
# Install dependencies for native modules
RUN apk add --no-cache python3 make g++
# Copy package files
COPY package*.json ./
# Install all dependencies
RUN npm ci
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Prune dev dependencies
RUN npm prune --production
# ============================================
# Production Stage
# ============================================
FROM node:22-alpine AS production
WORKDIR /app
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001
COPY --from=build --chown=nestjs:nodejs /app/dist ./dist
COPY --from=build --chown=nestjs:nodejs /app/node_modules ./node_modules
COPY --from=build --chown=nestjs:nodejs /app/package*.json ./
ENV NODE_ENV=production
ENV PORT=3000
USER nestjs
EXPOSE 3000
CMD ["sh", "-c", "node dist/main.js"]