Skip to content

Commit 026b46f

Browse files
committed
update:自动构建
1 parent 3d7693a commit 026b46f

5 files changed

Lines changed: 164 additions & 3 deletions

File tree

.dockerignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Git相关
2+
.git
3+
.gitignore
4+
5+
# Python相关
6+
__pycache__
7+
*.pyc
8+
*.pyo
9+
*.pyd
10+
.Python
11+
env
12+
pip-log.txt
13+
pip-delete-this-directory.txt
14+
.tox
15+
.coverage
16+
.coverage.*
17+
.cache
18+
nosetests.xml
19+
coverage.xml
20+
*.cover
21+
*.log
22+
.git
23+
.mypy_cache
24+
.pytest_cache
25+
.hypothesis
26+
27+
# 虚拟环境
28+
venv/
29+
env/
30+
ENV/
31+
32+
# IDE相关
33+
.vscode/
34+
.idea/
35+
*.swp
36+
*.swo
37+
*~
38+
39+
# 操作系统相关
40+
.DS_Store
41+
.DS_Store?
42+
._*
43+
.Spotlight-V100
44+
.Trashes
45+
ehthumbs.db
46+
Thumbs.db
47+
48+
# 日志文件
49+
logs/*.log
50+
51+
# 临时文件
52+
*.tmp
53+
*.temp
54+
55+
# Docker相关
56+
Dockerfile
57+
.dockerignore
58+
59+
# 文档
60+
README*.md
61+
LICENSE

.github/workflows/docker-image.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0
7+
workflow_dispatch:
8+
9+
jobs:
10+
release:
11+
name: Release Docker images
12+
runs-on: ubuntu-latest
13+
permissions:
14+
packages: write
15+
contents: write
16+
id-token: write
17+
issues: write
18+
steps:
19+
- name: Check Disk Space
20+
run: |
21+
df -h
22+
docker system df
23+
24+
- name: Clean up Docker resources
25+
run: |
26+
docker system prune -af
27+
docker builder prune -af
28+
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Login to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.TOKEN }}
41+
42+
- name: Extract version from tag
43+
id: get_version
44+
run: |
45+
if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
46+
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
47+
echo "IS_VERSION=true" >> $GITHUB_ENV
48+
else
49+
echo "VERSION=latest" >> $GITHUB_ENV
50+
echo "IS_VERSION=false" >> $GITHUB_ENV
51+
fi
52+
53+
# 构建 MCP Endpoint Server 镜像
54+
- name: Build and push mcp-endpoint-server
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
file: Dockerfile
59+
push: true
60+
tags: |
61+
${{ env.IS_VERSION == 'true' && format('ghcr.io/{0}:{1},ghcr.io/{0}:latest', github.repository, env.VERSION) || format('ghcr.io/{0}:latest', github.repository) }}
62+
platforms: linux/amd64,linux/arm64

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 第一阶段:构建Python依赖
2+
FROM python:3.10-slim AS builder
3+
4+
# 设置工作目录
5+
WORKDIR /app
6+
7+
# 复制依赖文件
8+
COPY requirements.txt .
9+
10+
# 安装Python依赖
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# 第二阶段:运行阶段
14+
FROM python:3.10-slim
15+
16+
# 设置工作目录
17+
WORKDIR /app
18+
19+
# 从构建阶段复制Python依赖
20+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
21+
22+
# 创建必要的目录
23+
RUN mkdir -p logs data
24+
25+
# 复制应用代码
26+
COPY . .
27+
28+
# 启动命令
29+
CMD ["python", "main.py"]

src/handlers/websocket_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import json
7-
import asyncio
87
from typing import Optional, Any
98
from urllib.parse import parse_qs, urlparse
109
from websockets.server import WebSocketServerProtocol

src/server.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ async def lifespan(app: FastAPI):
2626
"""应用生命周期管理"""
2727
# 启动时
2828
logger.info("MCP Endpoint Server 正在启动...")
29+
logger.info(f"======================================================")
30+
logger.info(
31+
f"接口地址: http://{config.get('server', 'host', '127.0.0.1')}:{config.getint('server', 'port', 8004)}/mcp_endpoint/health?key={config.get('server', 'key', '')}"
32+
)
33+
logger.info("=======上面的地址是websocket协议地址,请勿用浏览器访问=======")
2934
yield
3035
# 关闭时
3136
logger.info("MCP Endpoint Server 已关闭")
@@ -63,10 +68,15 @@ async def root():
6368

6469

6570
@app.get("/mcp_endpoint/health")
66-
async def health_check():
71+
async def health_check(key: str = None):
6772
"""健康检查"""
73+
# 验证key参数
74+
expected_key = config.get("server", "key", "")
75+
if not key or key != expected_key:
76+
return {"status": "key_error"}
77+
6878
stats = connection_manager.get_connection_stats()
69-
return {"status": "healthy", "connections": stats}
79+
return {"status": "success", "connections": stats}
7080

7181

7282
@app.websocket("/mcp_endpoint/mcp/")

0 commit comments

Comments
 (0)