-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (28 loc) · 919 Bytes
/
Dockerfile
File metadata and controls
39 lines (28 loc) · 919 Bytes
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
# 使用 Node.js 20 作为基础镜像
FROM node:20
# 安装 cron 和 curl
RUN apt-get update && apt-get install -y cron curl && rm -rf /var/lib/apt/lists/*
# 安装 pnpm
RUN npm install -g pnpm
# 设置工作目录
WORKDIR /app
# 复制源代码
COPY . .
# 清理可能存在的依赖文件
RUN rm -rf node_modules bun.lockb frontend/node_modules backend/node_modules
# 安装依赖
RUN pnpm install
RUN pnpm run build
# 创建 crontab 文件
RUN echo '* * * * * curl "http://localhost:8080/__scheduled?cron=*+*+*+*+*" > /proc/1/fd/1 2>&1' | crontab -
# 创建启动脚本
RUN echo '#!/bin/sh' > /start.sh && \
echo 'echo "Starting cron daemon..."' >> /start.sh && \
echo 'service cron start' >> /start.sh && \
echo 'echo "Starting application..."' >> /start.sh && \
echo 'pnpm run preview' >> /start.sh && \
chmod +x /start.sh
# 暴露端口
EXPOSE 8080
# 启动服务
CMD ["/start.sh"]