65 lines
1.1 KiB
Docker
65 lines
1.1 KiB
Docker
# Multi-stage build for production optimization
|
|
FROM node:18-alpine AS development
|
|
|
|
# Set working directory
|
|
WORKDIR /usr/src/app
|
|
|
|
# Copy package files
|
|
COPY package*.json yarn.lock ./
|
|
|
|
# Install dependencies
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Development command
|
|
CMD ["yarn", "start:dev"]
|
|
|
|
# Production build stage
|
|
FROM node:18-alpine AS build
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
# Copy package files
|
|
COPY package*.json yarn.lock ./
|
|
|
|
# Install dependencies
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN yarn build
|
|
|
|
# Production stage
|
|
FROM node:18-alpine AS production
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
# Copy package files
|
|
COPY package*.json yarn.lock ./
|
|
|
|
# Install only production dependencies
|
|
RUN yarn install --frozen-lockfile --production && yarn cache clean
|
|
|
|
# Copy built application
|
|
COPY --from=build /usr/src/app/dist ./dist
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nestjs -u 1001
|
|
|
|
# Change ownership of the app directory
|
|
USER nestjs
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Production command
|
|
CMD ["node", "dist/main"]
|