-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (47 loc) · 1.64 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (47 loc) · 1.64 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
# ============================================
# Stage 1: Build Frontend
# ============================================
FROM node:20-alpine AS frontend-builder
WORKDIR /app/client
COPY client/package*.json ./
RUN npm ci
COPY client/ ./
RUN npm run build
# ============================================
# Stage 2: Build Backend Dependencies
# ============================================
FROM node:20-alpine AS backend-builder
WORKDIR /app/server
COPY server/package*.json ./
RUN npm ci --only=production
# ============================================
# Stage 3: Production Image
# ============================================
FROM node:20-alpine AS production
RUN apk add --no-cache dumb-init
# backend root
WORKDIR /app/server
# Copy backend source code correctly
COPY server/ ./
# Copy backend node_modules into correct place
COPY --from=backend-builder /app/server/node_modules ./node_modules
# Copy frontend build output into correct backend location
COPY --from=frontend-builder /app/client/dist ./client/dist
# Create storage folder and empty indexStore.json to avoid ENOENT
# RUN mkdir -p /app/server/storage
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
ENV NODE_ENV=production
ENV PORT=8080
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s \
CMD node -e "require('http').get('http://localhost:${PORT}/health', r => process.exit(r.statusCode === 200 ? 0 : 1))"
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the server
CMD ["node", "src/server.js"]