Spaces:
Sleeping
Sleeping
Commit ·
1073da8
1
Parent(s): ba1bdb9
add supervisor.
Browse files- Dockerfile +6 -1
- fastapi/app.py → fast_app/fast_app.py +0 -0
- flask_app/flask_app.py +12 -0
- nginx/nginx.conf +12 -1
- requirements.txt +2 -0
- scripts/start.sh +2 -2
- supervisor/supervisor.conf +29 -0
Dockerfile
CHANGED
|
@@ -6,6 +6,8 @@ FROM python:3.9
|
|
| 6 |
# 安装运行时依赖
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
nginx \
|
|
|
|
|
|
|
| 9 |
libgomp1 \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
|
@@ -33,5 +35,8 @@ RUN chmod +x /app/scripts/start.sh
|
|
| 33 |
# 暴露端口
|
| 34 |
EXPOSE 7860
|
| 35 |
# 启动服务
|
| 36 |
-
CMD ["/app/scripts/start.sh"]
|
| 37 |
#CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# 安装运行时依赖
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
nginx \
|
| 9 |
+
supervisor \
|
| 10 |
+
curl \
|
| 11 |
libgomp1 \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
|
|
|
| 35 |
# 暴露端口
|
| 36 |
EXPOSE 7860
|
| 37 |
# 启动服务
|
| 38 |
+
#CMD ["/app/scripts/start.sh"]
|
| 39 |
#CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 40 |
+
|
| 41 |
+
# 启动 Supervisor
|
| 42 |
+
CMD ["/usr/bin/supervisord", "-n", "-c", "/app/supervisor/supervisord.conf"]
|
fastapi/app.py → fast_app/fast_app.py
RENAMED
|
File without changes
|
flask_app/flask_app.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from flask import Flask, jsonify
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
@app.route("/")
|
| 7 |
+
def read_root():
|
| 8 |
+
return jsonify({"service": "Flask", "status": "running"})
|
| 9 |
+
|
| 10 |
+
@app.route("/health")
|
| 11 |
+
def health_check():
|
| 12 |
+
return jsonify({"status": "healthy"})
|
nginx/nginx.conf
CHANGED
|
@@ -12,6 +12,10 @@ http {
|
|
| 12 |
server localhost:8000;
|
| 13 |
}
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
upstream django {
|
| 16 |
server localhost:8001;
|
| 17 |
}
|
|
@@ -56,7 +60,14 @@ http {
|
|
| 56 |
proxy_connect_timeout 60s;
|
| 57 |
proxy_send_timeout 60s;
|
| 58 |
proxy_read_timeout 60s;
|
| 59 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Django 媒体文件
|
| 62 |
location /media/ {
|
|
|
|
| 12 |
server localhost:8000;
|
| 13 |
}
|
| 14 |
|
| 15 |
+
upstream flaskapi {
|
| 16 |
+
server localhost:5000;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
upstream django {
|
| 20 |
server localhost:8001;
|
| 21 |
}
|
|
|
|
| 60 |
proxy_connect_timeout 60s;
|
| 61 |
proxy_send_timeout 60s;
|
| 62 |
proxy_read_timeout 60s;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
location /flaskapi/ {
|
| 66 |
+
proxy_pass http://flaskapi/;
|
| 67 |
+
proxy_set_header Host $host;
|
| 68 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 69 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 70 |
+
}
|
| 71 |
|
| 72 |
# Django 媒体文件
|
| 73 |
location /media/ {
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
fastapi
|
|
|
|
|
|
|
| 2 |
uvicorn[standard]
|
|
|
|
| 1 |
fastapi
|
| 2 |
+
flask
|
| 3 |
+
gunicorn
|
| 4 |
uvicorn[standard]
|
scripts/start.sh
CHANGED
|
@@ -9,9 +9,9 @@ echo "Server beginning ..."
|
|
| 9 |
echo "Current Directory: $(pwd)"; echo "CPU Info:"; lscpu; echo "Disk Usage:"; df -h; echo "Block Devices:"; lsblk
|
| 10 |
|
| 11 |
# 启动 Nginx // -g "daemon off;"
|
| 12 |
-
nginx -c "$(pwd)/nginx/nginx.conf"
|
| 13 |
|
| 14 |
# 启动 FastAPI // --workers 3
|
| 15 |
-
uvicorn
|
| 16 |
|
| 17 |
echo "Server started ..."
|
|
|
|
| 9 |
echo "Current Directory: $(pwd)"; echo "CPU Info:"; lscpu; echo "Disk Usage:"; df -h; echo "Block Devices:"; lsblk
|
| 10 |
|
| 11 |
# 启动 Nginx // -g "daemon off;"
|
| 12 |
+
#nginx -c "$(pwd)/nginx/nginx.conf"
|
| 13 |
|
| 14 |
# 启动 FastAPI // --workers 3
|
| 15 |
+
#uvicorn fast_app:app --app-dir ./fast_app --reload --host 127.0.0.1 --port 8000 --log-level info
|
| 16 |
|
| 17 |
echo "Server started ..."
|
supervisor/supervisor.conf
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
[supervisord]
|
| 3 |
+
nodaemon=true
|
| 4 |
+
user=root
|
| 5 |
+
logfile=/var/log/supervisor/supervisord.log
|
| 6 |
+
pidfile=/var/run/supervisord.pid
|
| 7 |
+
|
| 8 |
+
[program:nginx]
|
| 9 |
+
command=nginx -c "/app/nginx/nginx.conf"
|
| 10 |
+
autostart=true
|
| 11 |
+
autorestart=true
|
| 12 |
+
stdout_logfile=/var/log/nginx/nginx_stdout.log
|
| 13 |
+
stderr_logfile=/var/log/nginx/nginx_stderr.log
|
| 14 |
+
|
| 15 |
+
[program:fastapi]
|
| 16 |
+
command=uvicorn fast_app:app --reload --host 127.0.0.1 --port 8000 --log-level info
|
| 17 |
+
directory=/app/fast_app
|
| 18 |
+
autostart=true
|
| 19 |
+
autorestart=true
|
| 20 |
+
stdout_logfile=/var/log/supervisor/fastapi_stdout.log
|
| 21 |
+
stderr_logfile=/var/log/supervisor/fastapi_stderr.log
|
| 22 |
+
|
| 23 |
+
[program:flask]
|
| 24 |
+
command=gunicorn flask_app:app --bind 127.0.0.1:5000 --workers 2
|
| 25 |
+
directory=/app/flask_app
|
| 26 |
+
autostart=true
|
| 27 |
+
autorestart=true
|
| 28 |
+
stdout_logfile=/var/log/supervisor/flask_stdout.log
|
| 29 |
+
stderr_logfile=/var/log/supervisor/flask_stderr.log
|