-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (53 loc) · 1.89 KB
/
Dockerfile
File metadata and controls
70 lines (53 loc) · 1.89 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
# Multi-stage build for production optimization
FROM node:20-alpine AS base
# Install curl for health checks
RUN apk add --no-cache curl
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY server/package*.json ./server/
# Configure npm for better reliability
ARG NPM_CONFIG_FETCH_TIMEOUT=600000
ARG NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000
ARG NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=20000
ENV NPM_CONFIG_FETCH_TIMEOUT=$NPM_CONFIG_FETCH_TIMEOUT
ENV NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=$NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT
ENV NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=$NPM_CONFIG_FETCH_RETRY_MINTIMEOUT
# Install dependencies
RUN npm ci --only=production && npm cache clean --force
RUN cd server && npm install --only=production && npm cache clean --force
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
# Copy package files and install all dependencies (including devDependencies)
COPY package*.json ./
COPY server/package*.json ./server/
RUN npm ci
RUN cd server && npm install
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production image, copy all the files and run the app
FROM base AS runner
WORKDIR /app
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 appuser
# Copy built application
COPY --from=builder --chown=appuser:nodejs /app/dist ./dist
COPY --from=builder --chown=appuser:nodejs /app/server ./server
COPY --from=deps --chown=appuser:nodejs /app/node_modules ./node_modules
COPY --from=deps --chown=appuser:nodejs /app/server/node_modules ./server/node_modules
# Create logs directory
RUN mkdir -p logs server/logs
USER appuser
# Expose port
EXPOSE 5010
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5010/health || exit 1
# Start the application
CMD ["node", "server/server.js"]