-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
131 lines (111 loc) · 3.41 KB
/
Dockerfile
File metadata and controls
131 lines (111 loc) · 3.41 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
123
124
125
126
127
128
129
130
131
# FuturDocuments 单容器 Dockerfile
FROM node:18-alpine
# 设置工作目录
WORKDIR /app
# 安装 Python 和必要的系统依赖
RUN apk add --no-cache \
python3 \
py3-pip \
python3-dev \
build-base \
linux-headers \
git \
nginx \
supervisor
# 创建 Python 虚拟环境
RUN python3 -m venv /app/venv
# 复制 pdf-parser 目录
COPY pdf-parser /app/pdf-parser
# 安装 Python 依赖
RUN cd /app/pdf-parser && \
/app/venv/bin/pip install --upgrade pip && \
/app/venv/bin/pip install -r requirements.txt && \
/app/venv/bin/pip install -e .
# 复制并安装后端依赖
COPY futurdocuments-web/backend/package*.json /app/backend/
WORKDIR /app/backend
RUN npm ci --only=production
# 复制并安装前端依赖
COPY futurdocuments-web/frontend/package*.json /app/frontend/
WORKDIR /app/frontend
RUN npm ci --only=production
# 复制所有源代码
WORKDIR /app
COPY futurdocuments-web/backend/ /app/backend/
COPY futurdocuments-web/frontend/ /app/frontend/
COPY futurdocuments-web/config/ /app/config/
# 创建必要的目录
RUN mkdir -p /app/uploads /app/temp /var/log/supervisor
# 配置 Nginx
RUN rm /etc/nginx/http.d/default.conf
COPY <<EOF /etc/nginx/http.d/futurdocs.conf
server {
listen 80;
server_name localhost;
# 前端静态文件
location / {
proxy_pass http://localhost:3008;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
# API 请求转发到后端
location /api/ {
proxy_pass http://localhost:5008;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
# Socket.IO 转发
location /socket.io/ {
proxy_pass http://localhost:5008;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
# 配置 Supervisor
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx_error.log
[program:backend]
command=npm start
directory=/app/backend
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/backend.log
stderr_logfile=/var/log/supervisor/backend_error.log
environment=NODE_ENV=production,PORT=5008,PDF_PARSER_PATH=/app/pdf-parser,PYTHON_ENV=/app/venv/bin/python
[program:frontend]
command=npm start
directory=/app/frontend
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/frontend.log
stderr_logfile=/var/log/supervisor/frontend_error.log
environment=NODE_ENV=production,PORT=3008
EOF
# 设置环境变量
ENV NODE_ENV=production
ENV PDF_PARSER_PATH=/app/pdf-parser
ENV PYTHON_ENV=/app/venv/bin/python
# 暴露端口
EXPOSE 80
# 启动 Supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]