-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (86 loc) · 3.38 KB
/
Dockerfile
File metadata and controls
109 lines (86 loc) · 3.38 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
# ==============================================================================
# Multi-stage Dockerfile for GXQ Studio
# Supports: Railway, AWS, Azure, Alibaba Cloud, Docker Compose, VPS
# ==============================================================================
# ------------------------------------------------------------------------------
# Stage 1: Base Node Image
# ------------------------------------------------------------------------------
FROM node:20-alpine AS base
WORKDIR /app
RUN apk add --no-cache libc6-compat
# ------------------------------------------------------------------------------
# Stage 2: Backend Dependencies
# ------------------------------------------------------------------------------
FROM base AS backend-deps
COPY package*.json ./
COPY tsconfig.json ./
RUN npm ci --production=false
# ------------------------------------------------------------------------------
# Stage 3: Backend Builder
# ------------------------------------------------------------------------------
FROM backend-deps AS backend-builder
COPY src ./src
COPY api ./api
COPY lib ./lib
COPY scripts ./scripts
RUN npm run build:backend
# ------------------------------------------------------------------------------
# Stage 4: Backend Production
# ------------------------------------------------------------------------------
FROM base AS backend
ENV NODE_ENV=production
# Install production dependencies only
COPY package*.json ./
RUN npm ci --production --ignore-scripts
# Copy built files from builder
COPY --from=backend-builder /app/dist ./dist
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Create necessary directories
RUN mkdir -p /app/data /app/logs && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1); })"
# Start application (use unified server by default)
CMD ["node", "dist/src/server.js"]
# ------------------------------------------------------------------------------
# Stage 5: Full Stack (Backend + Webapp)
# For platforms that need both in one container
# ------------------------------------------------------------------------------
FROM base AS fullstack
# Install dependencies for both backend and webapp
COPY package*.json ./
COPY tsconfig.json ./
RUN npm ci --production=false
# Copy and build backend
COPY src ./src
COPY api ./api
COPY lib ./lib
COPY scripts ./scripts
RUN npm run build:backend
# Copy and build webapp
COPY webapp ./webapp
RUN cd webapp && npm ci && npm run build
# Install production dependencies only
RUN npm ci --production --ignore-scripts
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Create necessary directories
RUN mkdir -p /app/data /app/logs && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose ports (backend: 3000, webapp: 3001)
EXPOSE 3000 3001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1); })"
# Start both services (requires process manager or script)
CMD ["sh", "-c", "node dist/src/server.js & cd webapp && npm start"]