takatorury commited on
Commit
394952a
·
verified ·
1 Parent(s): cfc8dbf

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +130 -0
Dockerfile ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 基于教程中提到的包含中文字体和完整texlive的镜像
2
+ FROM wrm244/sharelatex:with-texlive-full
3
+
4
+ # 设置环境变量
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+ ENV TZ=Asia/Shanghai
7
+
8
+ # 安装必要的系统依赖
9
+ RUN apt-get update && apt-get install -y \
10
+ curl \
11
+ wget \
12
+ git \
13
+ python3 \
14
+ python3-pip \
15
+ nodejs \
16
+ npm \
17
+ nginx \
18
+ supervisor \
19
+ && rm -rf /var/lib/apt/lists/*
20
+
21
+ # 创建必要的目录
22
+ RUN mkdir -p /var/lib/sharelatex \
23
+ && mkdir -p /var/log/supervisor \
24
+ && mkdir -p /app
25
+
26
+ # 设置工作目录
27
+ WORKDIR /app
28
+
29
+ # 复制应用文件(如果有的话)
30
+ # COPY . /app
31
+
32
+ # 安装Python依赖(如果需要的话)
33
+ # COPY requirements.txt .
34
+ # RUN pip3 install -r requirements.txt
35
+
36
+ # 创建supervisor配置文件
37
+ RUN cat > /etc/supervisor/conf.d/supervisord.conf << 'EOF'
38
+ [unix_http_server]
39
+ file=/var/run/supervisor.sock
40
+ chmod=0700
41
+
42
+ [supervisord]
43
+ nodaemon=true
44
+ logfile=/var/log/supervisor/supervisord.log
45
+ pidfile=/var/run/supervisord.pid
46
+
47
+ [rpcinterface:supervisor]
48
+ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
49
+
50
+ [supervisorctl]
51
+ serverurl=unix:///var/run/supervisor.sock
52
+
53
+ [program:sharelatex]
54
+ command=/sbin/my_init -- /bin/bash -c "cd /overleaf/services/web && npm start"
55
+ autostart=true
56
+ autorestart=true
57
+ stderr_logfile=/var/log/supervisor/sharelatex.err.log
58
+ stdout_logfile=/var/log/supervisor/sharelatex.out.log
59
+ user=root
60
+ environment=HOME="/root",USER="root"
61
+
62
+ [program:nginx]
63
+ command=/usr/sbin/nginx -g "daemon off;"
64
+ autostart=true
65
+ autorestart=true
66
+ stderr_logfile=/var/log/supervisor/nginx.err.log
67
+ stdout_logfile=/var/log/supervisor/nginx.out.log
68
+ EOF
69
+
70
+ # 创建nginx配置
71
+ RUN cat > /etc/nginx/sites-available/default << 'EOF'
72
+ server {
73
+ listen 7860;
74
+ server_name _;
75
+
76
+ location / {
77
+ proxy_pass http://localhost:80;
78
+ proxy_set_header Host $host;
79
+ proxy_set_header X-Real-IP $remote_addr;
80
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
81
+ proxy_set_header X-Forwarded-Proto $scheme;
82
+ proxy_buffering off;
83
+ }
84
+ }
85
+ EOF
86
+
87
+ # 设置环境变量
88
+ ENV SHARELATEX_MONGO_URL=mongodb://127.0.0.1/sharelatex
89
+ ENV SHARELATEX_REDIS_HOST=127.0.0.1
90
+ ENV REDIS_HOST=127.0.0.1
91
+ ENV SHARELATEX_APP_NAME="Overleaf Community Edition"
92
+ ENV SHARELATEX_LISTEN_IP=0.0.0.0
93
+ ENV SHARELATEX_PORT=80
94
+
95
+ # 为Hugging Face Spaces设置特定环境变量
96
+ ENV GRADIO_SERVER_NAME="0.0.0.0"
97
+ ENV GRADIO_SERVER_PORT=7860
98
+
99
+ # 暴露端口(Hugging Face Spaces默认使用7860端口)
100
+ EXPOSE 7860
101
+
102
+ # 创建启动脚本
103
+ RUN cat > /start.sh << 'EOF'
104
+ #!/bin/bash
105
+
106
+ # 启动MongoDB
107
+ mongod --fork --logpath /var/log/mongodb.log --dbpath /var/lib/mongodb
108
+
109
+ # 启动Redis
110
+ redis-server --daemonize yes
111
+
112
+ # 等待数据库服务启动
113
+ sleep 5
114
+
115
+ # 启动supervisor管理的服务
116
+ exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
117
+ EOF
118
+
119
+ RUN chmod +x /start.sh
120
+
121
+ # 创建默认的数据目录
122
+ RUN mkdir -p /var/lib/mongodb \
123
+ && chown -R mongodb:mongodb /var/lib/mongodb
124
+
125
+ # 健康检查
126
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
127
+ CMD curl -f http://localhost:7860/ || exit 1
128
+
129
+ # 启动命令
130
+ CMD ["/start.sh"]