orztv commited on
Commit
5d4fe20
·
1 Parent(s): f2ef0bf
Files changed (5) hide show
  1. Dockerfile +12 -30
  2. README.md +1 -33
  3. app.py +0 -14
  4. nginx.conf +0 -46
  5. server.js +0 -25
Dockerfile CHANGED
@@ -1,35 +1,17 @@
1
- FROM nikolaik/python-nodejs:python3.10-nodejs20
 
2
 
3
- WORKDIR /home/pn/app
 
4
 
5
- # 复制 Python 和 Node.js 应用程序文件
6
- COPY --chown=pn:pn app.py server.js ./
7
 
8
- # 安装依赖
9
- RUN pip install flask gunicorn
10
- RUN npm install express
11
 
12
- # 安装 Nginx
13
- RUN apt-get update && apt-get install -y nginx
14
 
15
- # 配置 Nginx
16
- COPY nginx.conf /etc/nginx/nginx.conf
17
-
18
- # 创建日志目录并设置权限
19
- RUN mkdir -p /var/log/nginx /var/lib/nginx /tmp/client_temp /tmp/proxy_temp_path /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp && \
20
- chown -R pn:pn /var/log/nginx /var/lib/nginx /tmp/client_temp /tmp/proxy_temp_path /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp
21
-
22
- # 暴露端口
23
- EXPOSE 7860
24
-
25
- # 设置环境变量
26
- ENV FLASK_PORT=6000
27
- ENV NODE_PORT=7000
28
-
29
- # 切换到非root用户
30
- USER pn
31
-
32
- # 启动服务
33
- CMD nginx && \
34
- gunicorn -b 0.0.0.0:$FLASK_PORT app:app & \
35
- NODE_PORT=$NODE_PORT node server.js
 
1
+ # 使用官方 nocodb 镜像作为基础镜像
2
+ FROM nocodb/nocodb:latest
3
 
4
+ # 设置工作目录
5
+ WORKDIR /usr/app
6
 
7
+ # 创建数据目录
8
+ RUN mkdir -p /usr/app/data
9
 
10
+ # 暴露端口 8080
11
+ EXPOSE 8080
 
12
 
13
+ # 使用 dumb-init 作为入口点以正确处理信号
14
+ ENTRYPOINT ["/usr/bin/dumb-init", "--"]
15
 
16
+ # 设置默认命令
17
+ CMD ["node", "docker/start-with-health-check.js"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -5,40 +5,8 @@ colorFrom: gray
5
  colorTo: red
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
11
 
12
- 这个项目使用 Docker 来运行 Python Flask 和 Node.js 示例程序,并使用 Nginx 进行反向代理。
13
-
14
- ## 环境要求
15
-
16
- - Docker
17
-
18
- ## 使用方法
19
-
20
- 1. 构建 Docker 镜像:
21
- ```
22
- docker build -t hf-proxy .
23
- ```
24
-
25
- 2. 运行 Docker 容器:
26
- ```
27
- docker run -p 7860:7860 hf-proxy
28
- ```
29
-
30
- 3. 访问应用:
31
- - Flask 应用: http://localhost:7860/flask
32
- - Node.js 应用: http://localhost:7860/node
33
-
34
- ## 注意事项
35
-
36
- - 默认用户为 appuser (非 root)
37
- - Flask 应用运行在容器内部的 6000 端口
38
- - Node.js 应用运行在容器内部的 7000 端口
39
- - Nginx 反向代理运行在 7860 端口
40
-
41
- ## 健康检查
42
-
43
- - Flask 健康检查: http://localhost:7860/flask/health
44
- - Node.js 健康检查: http://localhost:7860/node/health
 
5
  colorTo: red
6
  sdk: docker
7
  pinned: false
8
+ app_port: 8080
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py DELETED
@@ -1,14 +0,0 @@
1
- from flask import Flask
2
-
3
- app = Flask(__name__)
4
-
5
- @app.route('/')
6
- def hello():
7
- return "Hello from Flask!"
8
-
9
- @app.route('/health')
10
- def health():
11
- return "OK", 200
12
-
13
- if __name__ == '__main__':
14
- app.run(host='0.0.0.0', port=6000, threaded=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
nginx.conf DELETED
@@ -1,46 +0,0 @@
1
- worker_processes auto;
2
- pid /tmp/nginx.pid;
3
-
4
- events {
5
- worker_connections 1024;
6
- }
7
-
8
- http {
9
- client_body_temp_path /tmp/client_temp;
10
- proxy_temp_path /tmp/proxy_temp_path;
11
- fastcgi_temp_path /tmp/fastcgi_temp;
12
- uwsgi_temp_path /tmp/uwsgi_temp;
13
- scgi_temp_path /tmp/scgi_temp;
14
-
15
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
16
- '$status $body_bytes_sent "$http_referer" '
17
- '"$http_user_agent" "$http_x_forwarded_for"';
18
-
19
- access_log /tmp/nginx_access.log main;
20
- error_log /tmp/nginx_error.log;
21
-
22
- server {
23
- listen 7860;
24
-
25
- # Configuration for Flask application
26
- location /flask {
27
- rewrite ^/flask$ /flask/ permanent;
28
- proxy_pass http://127.0.0.1:6000/;
29
- proxy_set_header Host $host;
30
- proxy_set_header X-Real-IP $remote_addr;
31
- }
32
-
33
- # Configuration for Node.js application
34
- location /node {
35
- rewrite ^/node$ /node/ permanent;
36
- proxy_pass http://127.0.0.1:7000/;
37
- proxy_set_header Host $host;
38
- proxy_set_header X-Real-IP $remote_addr;
39
- }
40
-
41
- # Redirect root to /flask
42
- location = / {
43
- return 302 /flask;
44
- }
45
- }
46
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server.js DELETED
@@ -1,25 +0,0 @@
1
- const express = require('express');
2
- const app = express();
3
- const port = 7000;
4
-
5
- app.get('/', (req, res) => {
6
- res.send('Hello from Node.js!');
7
- });
8
-
9
- app.get('/health', (req, res) => {
10
- res.status(200).send('OK');
11
- });
12
-
13
- app.use((err, req, res, next) => {
14
- console.error(err.stack);
15
- res.status(500).send('Something broke!');
16
- });
17
-
18
- app.listen(port, '0.0.0.0', () => {
19
- console.log(`Node.js server listening at http://0.0.0.0:${port}`);
20
- });
21
-
22
- process.on('uncaughtException', (err) => {
23
- console.error('Uncaught Exception:', err);
24
- process.exit(1);
25
- });