Docker · 1178 bytes Raw Blame History
1 # Multi-stage build for Vue.js client
2 FROM node:18-alpine AS builder
3
4 WORKDIR /app
5
6 # Copy package files
7 COPY package*.json ./
8 COPY ../shared ./shared
9
10 # Install dependencies
11 RUN npm ci --only=production
12
13 # Copy source code
14 COPY . .
15
16 # Build the application
17 RUN npm run build
18
19 # Production stage with nginx
20 FROM nginx:alpine
21
22 # Copy built assets
23 COPY --from=builder /app/dist /usr/share/nginx/html
24
25 # Copy nginx configuration
26 COPY nginx.conf /etc/nginx/nginx.conf
27
28 # Create non-root user
29 RUN addgroup -g 1001 -S nodejs && \
30 adduser -S zephyrfs -u 1001 -G nodejs
31
32 # Set ownership
33 RUN chown -R zephyrfs:nodejs /usr/share/nginx/html && \
34 chown -R zephyrfs:nodejs /var/cache/nginx && \
35 chown -R zephyrfs:nodejs /var/log/nginx && \
36 chown -R zephyrfs:nodejs /etc/nginx/conf.d
37
38 # Make directories writable
39 RUN touch /var/run/nginx.pid && \
40 chown -R zephyrfs:nodejs /var/run/nginx.pid
41
42 # Switch to non-root user
43 USER zephyrfs
44
45 # Expose port
46 EXPOSE 8080
47
48 # Health check
49 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
50 CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
51
52 # Start nginx
53 CMD ["nginx", "-g", "daemon off;"]