diff --git a/mvcar/Dockerfile b/mvcar/Dockerfile new file mode 100644 index 0000000..d04a140 --- /dev/null +++ b/mvcar/Dockerfile @@ -0,0 +1,35 @@ +# Dockerfile +FROM python:3.9-slim + +# 安装nginx +RUN apt-get update && apt-get install -y \ + nginx \ + && rm -rf /var/lib/apt/lists/* + +# 创建应用目录 +WORKDIR /app + +# 复制后端文件 +COPY backend/ ./backend/ +COPY frontend/ /var/www/html/ + +# 安装Python依赖 +RUN pip install --no-cache-dir -r backend/requirements.txt + +# 创建数据和日志目录 +RUN mkdir -p data logs + +# 配置nginx +COPY nginx/nginx.conf /etc/nginx/sites-available/default + +# 暴露端口 +EXPOSE 80 + +# 启动脚本 +COPY sbin/start.sh /start.sh +RUN chmod +x /start.sh + +# 初始化数据库 +RUN python backend/init_db.py + +ENTRYPOINT ["/start.sh"] \ No newline at end of file diff --git a/mvcar/docker-compose.yaml b/mvcar/docker-compose.yaml new file mode 100644 index 0000000..0073c04 --- /dev/null +++ b/mvcar/docker-compose.yaml @@ -0,0 +1,10 @@ +version: '3.8' + +services: + mvcar: + build: . + ports: + - "80:80" + volumes: + - ./data:/app/data + - ./logs:/app/logs \ No newline at end of file diff --git a/mvcar/nginx/nginx.conf b/mvcar/nginx/nginx.conf new file mode 100644 index 0000000..998a22a --- /dev/null +++ b/mvcar/nginx/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name localhost; + + # 前端静态文件 + location / { + root /var/www/html; + index index.html; + try_files $uri $uri/ =404; + } + + # API请求代理到后端Flask应用 + location /api/ { + proxy_pass http://127.0.0.1:5000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + # 健康检查端点 + location /health { + proxy_pass http://127.0.0.1:5000; + } +} \ No newline at end of file diff --git a/mvcar/readme.md b/mvcar/readme.md index b64ecf5..a3127ed 100644 --- a/mvcar/readme.md +++ b/mvcar/readme.md @@ -10,4 +10,32 @@ ## 安装与运行 -1. 安装Python依赖: \ No newline at end of file +1. 安装Python依赖: + + +mvcar/ +├── backend/ +│ ├── app.py +│ ├── init_db.py +│ ├── view_logs.py +│ └── requirements.txt +├── frontend/ +│ ├── index.html +│ ├── result.html +│ ├── css/ +│ └── js/ +├── data/ +├── logs/ +├── Dockerfile +├── nginx.conf +├── start.sh +└── docker-compose.yml (可选) + +# 构建Docker镜像 +docker build -t mvcar-app . + +# 运行容器 +docker run -d -p 80:80 --name mvcar-container mvcar-app + +# 或者使用docker-compose(如果创建了docker-compose.yml) +docker-compose up --build -d \ No newline at end of file diff --git a/mvcar/sbin/start.sh b/mvcar/sbin/start.sh new file mode 100644 index 0000000..0864cde --- /dev/null +++ b/mvcar/sbin/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# 启动后端Flask应用 +cd /app/backend +nohup python app.py > /app/logs/flask.log 2>&1 & + +# 启动nginx +nginx -g "daemon off;" \ No newline at end of file diff --git a/mvcar/start_vscode.bat b/mvcar/start_vscode.bat new file mode 100644 index 0000000..a32aec6 --- /dev/null +++ b/mvcar/start_vscode.bat @@ -0,0 +1,2 @@ +@echo off +start "" code .