-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
53 lines (40 loc) · 1.12 KB
/
Dockerfile
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
# 构建阶段
FROM node:20-alpine as builder
WORKDIR /app
# 首先只复制 package 文件以利用缓存
COPY package*.json ./
RUN npm install
# 复制源代码和其他文件
COPY . .
# 构建项目
RUN npm run build
# 运行阶段
FROM node:20-alpine
WORKDIR /app
# 复制构建产物和必要文件
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/assets ./assets
# 创建音频文件夹
RUN mkdir -p /podcasts && chmod 755 /podcasts
# 设置环境变量
ENV NODE_ENV=production \
PORT=3000 \
AUDIO_DIR=/podcasts \
PUID=1000 \
PGID=1000
# 创建启动脚本
RUN printf '%s\n' \
'#!/bin/sh' \
'chown -R $PUID:$PGID /app/dist /app/node_modules /app/assets /podcasts' \
'exec node dist/index.js' \
> /entrypoint.sh && \
chmod +x /entrypoint.sh
# 暴露端口
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT}/podcasts || exit 1
# 启动命令
CMD ["/entrypoint.sh"]