-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (42 loc) · 1.83 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (42 loc) · 1.83 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
# Alternative production-optimized Dockerfile
# Multi-stage build with better caching and security
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Install dependencies first (better caching)
COPY ./docs/package*.json ./
RUN npm ci
# Copy source and build
COPY ./docs .
RUN npm run docs:build
# Compress built files in place to save space
RUN apk add --no-cache gzip && \
cd /app/.vitepress/dist && \
find . -type f \( -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.json" -o -name "*.xml" -o -name "*.svg" -o -name "*.txt" \) -exec gzip -9 -v {} \;
# Production stage with nginx
FROM nginx:1.25-alpine AS production
# Install security updates
RUN apk upgrade --no-cache
# Create non-root user for nginx
RUN addgroup -g 1001 -S nginx-user && \
adduser -S -D -H -u 1001 -h /var/cache/nginx -s /sbin/nologin -G nginx-user -g nginx-user nginx-user
# Copy built site with compressed files
COPY --from=builder --chown=nginx-user:nginx-user /app/.vitepress/dist /usr/share/nginx/html
# Copy nginx configuration
COPY --chown=nginx-user:nginx-user nginx/nginx.conf /etc/nginx/nginx.conf
# Remove default nginx conf (listen 80 fails as non-root) and create includes.d dir
RUN rm -f /etc/nginx/conf.d/default.conf && \
mkdir -p /etc/nginx/conf.d /etc/nginx/includes.d
# Create necessary directories and set permissions
RUN mkdir -p /var/cache/nginx /var/log/nginx /tmp && \
chown -R nginx-user:nginx-user /var/cache/nginx /var/log/nginx /etc/nginx /usr/share/nginx/html /tmp && \
chmod -R 755 /usr/share/nginx/html && \
chmod 777 /tmp
# Switch to non-root user
USER nginx-user
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:9002/health || exit 1
EXPOSE 9002
# Start nginx
CMD ["nginx", "-g", "daemon off;"]