From e1f26abb990df91f8879e54152f67780c471ac4e Mon Sep 17 00:00:00 2001 From: tangyi Date: Fri, 9 May 2025 18:28:02 +0800 Subject: [PATCH] =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=20Docker=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E5=8C=85=E5=90=AB=20Dockerfile=20?= =?UTF-8?q?=E5=92=8C=20.dockerignore=20=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README=20=E4=BB=A5=E8=AF=B4=E6=98=8E=20Doc?= =?UTF-8?q?ker=20=E9=83=A8=E7=BD=B2=E6=96=B9=E6=B3=95=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BE=9D=E8=B5=96=E7=89=88=E6=9C=AC=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20Python=203.12.3=20=E5=8F=8A=E4=BB=A5=E4=B8=8A?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 32 ++++++++++++++++++ .github/workflows/docker-publish.yml | 50 ++++++++++++++++++++++++++++ Dockerfile | 24 +++++++++++++ README.md | 45 +++++++++++++++++++++++-- requirements.txt | 9 ++--- 5 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..57876c0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +# 操作系统和编辑器临时文件 +__MACOSX +.DS_Store +*.code-workspace +.vscode +.idea +.history +.cursorrules +.cursor + +# Python 缓存和测试 +**/__pycache__/ +__pycache__/ +*.pyc +*.pyo +*.pyd +*.swp +.pytest_cache/ +.coverage + +# Node/Vendor/依赖 +node_modules/ +vendor/ +requirements-dev.txt + +# 版本控制和文档 +.git +docs/ +tests/ + +# 环境变量 +.env \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..09656d6 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,50 @@ +name: Docker Build and Publish + +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: docker.io + IMAGE_NAME: mangooer/mysql-mcp-server-sse + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=tag + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=sha,format=short + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59ed607 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.12-slim + +RUN apt-get update && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# 复制本地代码到镜像 +COPY . . + +# 自动生成 .env(如不存在则复制 example.env) +RUN [ -f .env ] || cp example.env .env + +# 安装依赖 +RUN pip install --no-cache-dir -r requirements.txt + +# 暴露端口(如需) +EXPOSE 3000 + +# 支持环境变量覆盖 +ENV HOST=0.0.0.0 \ + PORT=3000 + +CMD ["python", "-m", "src.server"] \ No newline at end of file diff --git a/README.md b/README.md index 760577c..07411aa 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This project is a MySQL query server based on the MCP framework, supporting real - 敏感信息自动隐藏与自定义 - 灵活的环境变量配置 - 完善的日志与错误处理 +- Docker支持,快速部署 - Built on FastMCP framework, high-performance async - Connection pool for high concurrency, with flexible parameter tuning @@ -31,21 +32,59 @@ This project is a MySQL query server based on the MCP framework, supporting real - Automatic and customizable sensitive info masking - Flexible environment variable configuration - Robust logging & error handling +- Docker support for quick deployment --- ## 3. 快速开始 / Quick Start -### 安装依赖 / Install Dependencies +### Docker 方式 / Docker Method + +```bash +# 拉取镜像 +docker pull mangooer/mysql-mcp-server-sse:latest + +# 运行容器 +docker run -d \ + --name mysql-mcp-server-sse \ + -e HOST=0.0.0.0 \ + -e PORT=3000 \ + -e MYSQL_HOST=your_mysql_host \ + -e MYSQL_PORT=3306 \ + -e MYSQL_USER=your_mysql_user \ + -e MYSQL_PASSWORD=your_mysql_password \ + -e MYSQL_DATABASE=your_database \ + -p 3000:3000 \ + mangooer/mysql-mcp-server-sse:latest +``` + +Windows PowerShell 格式: +```powershell +docker run -d ` + --name mysql-mcp-server-sse ` + -e HOST=0.0.0.0 ` + -e PORT=3000 ` + -e MYSQL_HOST=your_mysql_host ` + -e MYSQL_PORT=3306 ` + -e MYSQL_USER=your_mysql_user ` + -e MYSQL_PASSWORD=your_mysql_password ` + -e MYSQL_DATABASE=your_database ` + -p 3000:3000 ` + mangooer/mysql-mcp-server-sse:latest +``` + +### 源码方式 / Source Code Method + +#### 安装依赖 / Install Dependencies ```bash pip install -r requirements.txt ``` -### 配置环境变量 / Configure Environment Variables +#### 配置环境变量 / Configure Environment Variables 复制`.env.example`为`.env`,并根据实际情况修改。 Copy `.env.example` to `.env` and modify as needed. -### 启动服务 / Start the Server +#### 启动服务 / Start the Server ```bash python -m src.server ``` diff --git a/requirements.txt b/requirements.txt index 26bb3a8..71ebf59 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -mcp>=0.1.0 -aiomysql==0.2.0 -python-dotenv>=0.19.0 -sqlparse>=0.4.2 \ No newline at end of file +# 需要 Python 3.12.3 及以上版本 / Requires Python >=3.12.3 +mcp>=1.4.1 +aiomysql>=0.2.0 +python-dotenv>=1.0.1 +sqlparse>=0.5.3 \ No newline at end of file