-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathDockerfile
More file actions
104 lines (78 loc) · 2.43 KB
/
Dockerfile
File metadata and controls
104 lines (78 loc) · 2.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# ============================================
# Multi-stage Dockerfile for axios-docs
# ============================================
# Best practices applied:
# - Multi-stage builds for smaller final image
# - Non-root user for security
# - Layer caching optimization
# - .dockerignore for build context efficiency
# - Health checks for production readiness
# - Proper signal handling with tini
# ============================================
# ==================== BUILD STAGE ====================
FROM node:20-alpine AS builder
# Install build dependencies (sharp requires these)
RUN apk add --no-cache \
python3 \
make \
g++ \
vips-dev
# Set working directory
WORKDIR /app
# Copy package files first (layer caching)
COPY package*.json ./
# Install dependencies
# Using ci for reproducible builds
RUN npm ci --only=production=false
# Copy source files
COPY . .
# Build the static site
RUN npm run build
# ==================== PRODUCTION STAGE ====================
FROM nginx:alpine AS production
# Install tini for proper signal handling
RUN apk add --no-cache tini
# Create non-root user for nginx
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
# Copy custom nginx configuration
COPY docker/nginx.conf /etc/nginx/nginx.conf
# Copy built static files from builder stage
COPY --from=builder /app/public /usr/share/nginx/html
# Set ownership
RUN chown -R appuser:appgroup /usr/share/nginx/html && \
chown -R appuser:appgroup /var/cache/nginx && \
chown -R appuser:appgroup /var/log/nginx && \
touch /run/nginx.pid && \
chown appuser:appgroup /run/nginx.pid
# Switch to non-root user
USER appuser
# Expose port 8080 (non-privileged port)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
# Use tini as init system
ENTRYPOINT ["/sbin/tini", "--"]
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
# ==================== DEVELOPMENT STAGE ====================
FROM node:20-alpine AS development
# Install build dependencies
RUN apk add --no-cache \
python3 \
make \
g++ \
vips-dev
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies including devDependencies
RUN npm ci
# Copy source files
COPY . .
# Expose development server port
EXPOSE 8080
# Start development server
CMD ["npm", "run", "server"]