-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
80 lines (60 loc) · 2.02 KB
/
Copy pathDockerfile
File metadata and controls
80 lines (60 loc) · 2.02 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
80
# Multi-stage Docker build for WeInsure platform
# Stage 1: Build frontend
FROM node:18-alpine AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci --only=production
COPY frontend/ ./
RUN npm run build
# Stage 2: Build backend and oracle
FROM node:18-alpine AS backend-builder
WORKDIR /app
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY oracle-adapter/package*.json ./oracle-adapter/
RUN npm ci --only=production
RUN cd backend && npm ci --only=production
RUN cd oracle-adapter && npm ci --only=production
# Stage 3: Production image
FROM node:18-alpine AS production
# Install PM2 globally
RUN npm install -g pm2
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY oracle-adapter/package*.json ./oracle-adapter/
# Install production dependencies
RUN npm ci --only=production
RUN cd backend && npm ci --only=production
RUN cd oracle-adapter && npm ci --only=production
# Copy application code
COPY backend/ ./backend/
COPY oracle-adapter/ ./oracle-adapter/
COPY scripts/ ./scripts/
COPY contracts/ ./contracts/
COPY hardhat.config.js ./
COPY ecosystem.config.js ./
# Copy built frontend from previous stage
COPY --from=frontend-builder /app/frontend/.next ./frontend/.next
COPY --from=frontend-builder /app/frontend/public ./frontend/public
COPY --from=frontend-builder /app/frontend/package*.json ./frontend/
COPY frontend/next.config.js ./frontend/
# Install frontend production dependencies
RUN cd frontend && npm ci --only=production
# Create logs directory
RUN mkdir -p logs
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S weinsure -u 1001
# Change ownership of the app directory
RUN chown -R weinsure:nodejs /app
USER weinsure
# Expose ports
EXPOSE 3000 3001 3002
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node scripts/health-check.js || exit 1
# Start all services with PM2
CMD ["pm2-runtime", "start", "ecosystem.config.js", "--env", "production"]