-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (57 loc) · 1.97 KB
/
Copy pathDockerfile
File metadata and controls
79 lines (57 loc) · 1.97 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
# Multi-stage build for ReconSpec application
# Stage 1: Build stage
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Install pnpm
RUN npm install -g pnpm
# Copy package.json and pnpm-workspace.yaml files
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
# Copy workspace packages
COPY shared/package.json shared/tsconfig.json ./shared/
COPY server/package.json server/tsconfig.json ./server/
COPY client/package.json client/tsconfig.json ./client/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source files
COPY shared/ ./shared/
COPY server/ ./server/
COPY client/ ./client/
# Build shared package first
RUN pnpm --filter shared build
# Build server
RUN pnpm --filter server build
# Build client
RUN pnpm --filter client build
# Stage 2: Production stage
FROM node:20-alpine AS production
# Install pnpm
RUN npm install -g pnpm
# Set working directory
WORKDIR /app
# Copy package.json and pnpm-workspace.yaml files
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
# Copy workspace packages
COPY shared/package.json shared/tsconfig.json ./shared/
COPY server/package.json server/tsconfig.json ./server/
# Install only production dependencies
RUN pnpm install --frozen-lockfile --prod
# Copy built artifacts
COPY --from=builder /app/shared/dist ./shared/dist
COPY --from=builder /app/server/dist ./server/dist
COPY --from=builder /app/client/dist ./client/dist
# Copy server source files for runtime
COPY server/src ./server/src
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Change ownership of the app directory
RUN chown -R nextjs:nodejs /app
USER nextjs
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3001/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
# Start the server
CMD ["node", "server/dist/index.js"]