完善docker配置

This commit is contained in:
小贺
2025-09-02 22:41:02 +08:00
parent 8de03156e1
commit 6b5603df84
10 changed files with 121 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
name: New MCP server
version: 0.0.1
schema: v1
mcpServers:
- name: New MCP server
command: npx
args:
- -y
- <your-mcp-server>
env: {}

View File

@@ -0,0 +1,7 @@
name: New prompt
version: 0.0.1
schema: v1
prompts:
- name: 中文做答
description: New prompt
prompt: 接下来的回复你需要使用中文作答

View File

@@ -0,0 +1,5 @@
---
description: A description of your rule
---
你需要使用中文作答

26
app/docker-compose.yml Normal file
View File

@@ -0,0 +1,26 @@
version: '3.8'
services:
frontend:
build:
context: ./front
dockerfile: dockerfile
ports:
- "80:80"
depends_on:
- backend
networks:
- app-network
backend:
build:
context: ./backend
dockerfile: dockerfile
ports:
- "5000:5000"
networks:
- app-network
networks:
app-network:
driver: bridge

31
app/front/nginx.conf Normal file
View File

@@ -0,0 +1,31 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 配置前端路由支持SPA单页应用
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# 处理静态文件
location / {
try_files $uri $uri/ /index.html;
}
# 代理API请求到后端
location /api/ {
proxy_pass http://backend: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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

14
backend/dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM python:3.11-slim
WORKDIR /app
# 安装依赖
RUN pip install --no-cache-dir fastapi==0.115.8 uvicorn[standard]==0.34.8 python-multipart
# 复制代码
COPY . .
# 暴露端口
EXPOSE 5000
# 启动命令
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

View File

@@ -1,10 +1,20 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn import uvicorn
import random import random
app = FastAPI() app = FastAPI()
# 添加CORS中间件允许所有来源
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 在生产环境中应该指定具体的域名
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/") @app.get("/")
async def root(): async def root():
return {"message": "Hello World"} return {"message": "Hello World"}

2
backend/requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
fastapi==0.115.8
uvicorn[standard]==0.34.8

15
front/dockerfile Normal file
View File

@@ -0,0 +1,15 @@
# 构建阶段
FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# 生产阶段
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
# 复制nginx配置
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -6,5 +6,5 @@ import App from './App.tsx'
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<App /> <App />
</StrictMode>, </StrictMode>
) )