-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
60 lines (43 loc) · 1.58 KB
/
Dockerfile.backend
File metadata and controls
60 lines (43 loc) · 1.58 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
# Build stage
FROM node:20-alpine AS builder
# Install build dependencies
RUN apk add --no-cache python3 make g++
WORKDIR /app
# Copy package files (support both npm and pnpm)
COPY package.json package-lock.json* pnpm-lock.yaml* ./
# Install dependencies (prefer npm if package-lock.json exists)
RUN if [ -f package-lock.json ]; then \
npm ci; \
elif [ -f pnpm-lock.yaml ]; then \
corepack enable && corepack prepare pnpm@latest --activate && pnpm install --frozen-lockfile; \
else \
npm install; \
fi
# Copy source code
COPY . .
# Build TypeScript (生成 dist,包括迁移脚本)
RUN npm run build
# 只保留生产依赖,避免在生产阶段再次 npm install
RUN npm prune --omit=dev
# Production stage
FROM node:20-alpine
# Install FFmpeg for video processing and netcat for health checks
RUN apk add --no-cache ffmpeg netcat-openbsd
WORKDIR /app
# 直接使用 builder 已安装并 prune 过的 node_modules,不再在此阶段 npm ci
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
# Copy built files from builder (包括迁移文件)
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/bootstrap.js ./
COPY --from=builder /app/docker-entrypoint.sh ./
# Create required directories
RUN mkdir -p logs temp config && chmod +x docker-entrypoint.sh
ENV APP_PORT=7001
# Expose port
EXPOSE 7001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \
CMD sh -c 'nc -z localhost "${APP_PORT:-7001}" || exit 1'
# Start application
ENTRYPOINT ["./docker-entrypoint.sh"]