-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (58 loc) · 1.71 KB
/
Dockerfile
File metadata and controls
78 lines (58 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Multi-stage Docker build for StrellerMinds Backend
FROM node:18-alpine AS base
# Install system dependencies
RUN apk add --no-cache \
dumb-init \
curl \
bash \
&& rm -rf /var/cache/apk/*
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY tsconfig*.json ./
# Development stage
FROM base AS development
ENV NODE_ENV=development
RUN npm ci --include=dev --legacy-peer-deps
COPY . .
EXPOSE 3000
CMD ["dumb-init", "npm", "run", "start:dev"]
# Build stage
FROM base AS build
ENV NODE_ENV=production
# Install all dependencies (including dev for build)
RUN npm ci --include=dev --legacy-peer-deps
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Remove dev dependencies
RUN npm prune --production --legacy-peer-deps && npm cache clean --force
# Production stage
FROM node:18-alpine AS production
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init curl
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001
# Set working directory
WORKDIR /app
# Copy built application and dependencies
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 ./
# Create necessary directories
RUN mkdir -p /app/logs && chown nestjs:nodejs /app/logs
# Switch to non-root user
USER nestjs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Set environment variables
ENV NODE_ENV=production
ENV PORT=3000
# Start the application
CMD ["dumb-init", "node", "dist/main.js"]