-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·122 lines (91 loc) · 2.7 KB
/
Dockerfile
File metadata and controls
executable file
·122 lines (91 loc) · 2.7 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Multi-stage Dockerfile for RCE Backend
# Supports development, test, and production environments
# ================================
# Base Stage - Common setup
# ================================
FROM node:20-alpine AS base
# Install system dependencies
RUN apk add --no-cache \
curl \
bash \
git \
docker-cli \
&& rm -rf /var/cache/apk/*
# Create app directory
WORKDIR /app
# Create nodejs user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 -G nodejs
# Copy package files
COPY package.json yarn.lock ./
# ================================
# Dependencies Stage
# ================================
FROM base AS dependencies
# Install all dependencies (including dev dependencies)
RUN yarn install --frozen-lockfile
# ================================
# Development Stage
# ================================
FROM dependencies AS development
# Copy source code
COPY . .
# Change ownership to nodejs user
RUN chown -R nodejs:nodejs /app
USER nodejs
# Expose port and debug port
EXPOSE 5000 9229
# Health check
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Start development server with debug support
CMD ["yarn", "dev"]
# ================================
# Test Stage
# ================================
FROM dependencies AS test
# Copy source code
COPY . .
# Build the application for testing
RUN yarn build
# Change ownership to nodejs user
RUN chown -R nodejs:nodejs /app
USER nodejs
# Expose port
EXPOSE 5000
# Health check
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Default command for tests
CMD ["yarn", "test"]
# ================================
# Builder Stage for Production
# ================================
FROM dependencies AS builder
# Copy source code
COPY . .
# Build the application
RUN yarn build
# ================================
# Production Stage
# ================================
FROM base AS production
# Install only production dependencies
RUN yarn install --frozen-lockfile --production && yarn cache clean
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./package.json
# Create logs directory
RUN mkdir -p /app/logs
# Change ownership to nodejs user
RUN chown -R nodejs:nodejs /app
USER nodejs
# Expose port
EXPOSE 5000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:5000/health', (res) => { \
if(res.statusCode === 200) process.exit(0); else process.exit(1); \
}).on('error', () => process.exit(1))"
# Start the application
CMD ["yarn", "start"]