Compare commits

...

6 Commits

Author SHA1 Message Date
CJACK.
a1b3f122a7 Merge pull request #6 from CJackHwang/cto-task-goal-ds2api-docker-docker-exploration-findings-files-examine
Add decoupled Docker support for ds2api
2026-02-04 01:10:54 +08:00
cto-new[bot]
43cb68cc1d Add decoupled Docker support with zero-intrusion design 2026-02-03 17:07:22 +00:00
CJACK.
06ae417dad Update README.MD
更新webui展示图片
2026-02-03 13:31:49 +08:00
CJACK.
28b70ca26c Update README.MD 2026-02-03 13:31:04 +08:00
CJACK
ee2dac28bd chore: remove debug logs 2026-02-01 21:47:23 +08:00
CJACK
db28b4e93e fix: simplify vercel.json and add debug logs for static file issues 2026-02-01 21:41:05 +08:00
8 changed files with 289 additions and 65 deletions

69
.dockerignore Normal file
View File

@@ -0,0 +1,69 @@
# Git
.git
.gitignore
# Python
__pycache__
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# 虚拟环境
venv/
env/
ENV/
.venv
# 环境配置(通过 docker-compose 挂载或环境变量传递)
.env
.env.local
.env.*.local
config.json
# 开发工具
.vscode/
.idea/
*.swp
*.swo
*~
# 测试
tests/
.pytest_cache/
.coverage
htmlcov/
# Node.js / WebUI 开发依赖
node_modules/
webui/node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# 文档
*.md
!README*.md
# CI/CD
.github/
.releaserc.json
# 其他
.DS_Store
Thumbs.db

158
DEPLOY.md
View File

@@ -7,6 +7,7 @@
## 目录
- [Vercel 部署(推荐)](#vercel-部署推荐)
- [Docker 部署(推荐)](#docker-部署推荐)
- [本地开发](#本地开发)
- [生产环境部署](#生产环境部署)
- [常见问题](#常见问题)
@@ -148,6 +149,108 @@ npm run build
---
## Docker 部署(推荐)
Docker 部署采用**零侵入、解耦设计**
- Dockerfile 仅执行标准 Python 项目操作,不硬编码任何项目特定配置
- 所有配置通过环境变量和 `.env` 文件管理
- **主代码更新时只需重新构建镜像,无需修改 Docker 配置**
### 快速开始Docker Compose
```bash
# 1. 复制环境变量模板
cp .env.example .env
# 编辑 .env填写 DS2API_ADMIN_KEY 和 DS2API_CONFIG_JSON
# 2. 启动服务
docker-compose up -d
# 3. 查看日志
docker-compose logs -f
# 4. 主代码更新后重新构建
docker-compose up -d --build
```
### 配置文件挂载方式
如需使用 `config.json` 而非环境变量:
```yaml
# docker-compose.yml
services:
ds2api:
build: .
ports:
- "5001:5001"
environment:
- DS2API_ADMIN_KEY=your-admin-key
volumes:
- ./config.json:/app/config.json:ro
restart: unless-stopped
```
### Docker 命令行部署
```bash
# 构建镜像
docker build -t ds2api:latest .
# 使用环境变量运行
docker run -d \
--name ds2api \
-p 5001:5001 \
-e DS2API_ADMIN_KEY=your-admin-key \
-e DS2API_CONFIG_JSON='{"keys":["api-key"],"accounts":[...]}' \
--restart unless-stopped \
ds2api:latest
# 或使用配置文件挂载
docker run -d \
--name ds2api \
-p 5001:5001 \
-e DS2API_ADMIN_KEY=your-admin-key \
-v $(pwd)/config.json:/app/config.json:ro \
--restart unless-stopped \
ds2api:latest
```
### 开发模式(热重载)
```bash
# 使用开发配置启动,代码修改实时生效
docker-compose -f docker-compose.dev.yml up
```
开发模式特性:
- 源代码挂载到容器,修改即时生效
- 日志级别设为 DEBUG
- 自动读取本地 `config.json`
### 维护命令
```bash
# 查看容器状态
docker-compose ps
# 查看日志
docker-compose logs -f ds2api
# 重启服务
docker-compose restart
# 停止服务
docker-compose down
# 完全重建(清除缓存)
docker-compose down
docker-compose build --no-cache
docker-compose up -d
```
---
## 生产环境部署
### 使用 systemd (Linux)
@@ -231,52 +334,6 @@ server {
}
```
### Docker 部署(可选)
```dockerfile
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5001
CMD ["python", "app.py"]
```
```bash
# 构建镜像
docker build -t ds2api .
# 运行容器
docker run -d \
--name ds2api \
-p 5001:5001 \
-e DS2API_ADMIN_KEY=your-admin-key \
-e DS2API_CONFIG_JSON='{"keys":["api-key"],"accounts":[...]}' \
ds2api
```
### Docker Compose
```yaml
# docker-compose.yml
version: '3.8'
services:
ds2api:
build: .
ports:
- "5001:5001"
environment:
- DS2API_ADMIN_KEY=${DS2API_ADMIN_KEY}
- DS2API_CONFIG_JSON=${DS2API_CONFIG_JSON}
restart: unless-stopped
```
---
## 常见问题
@@ -312,6 +369,15 @@ pip install -r requirements.txt
# 重启服务
```
**Docker 部署**:
```bash
# 拉取最新代码
git pull origin main
# 重新构建并启动(无需修改 Docker 配置)
docker-compose up -d --build
```
**Vercel 部署**:
- 项目会自动从 GitHub 同步更新
- 或在 Vercel 控制台手动触发重新部署

20
Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
# DS2API Docker 镜像
# 采用极简、零侵入设计,所有配置通过环境变量传递
# 主代码更新时只需重新构建镜像,无需修改 Dockerfile
FROM python:3.11-slim
WORKDIR /app
# 安装依赖(利用 Docker 缓存层)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 复制整个项目(保留原始目录结构)
COPY . .
# 暴露服务端口
EXPOSE 5001
# 启动命令(依赖项目自身的启动逻辑)
CMD ["python", "app.py"]

View File

@@ -4,9 +4,18 @@
![Stars](https://img.shields.io/github/stars/CJackHwang/ds2api.svg)
![Forks](https://img.shields.io/github/forks/CJackHwang/ds2api.svg)
[![Version](https://img.shields.io/badge/version-1.6.11-blue.svg)](version.txt)
[![Docker](https://img.shields.io/badge/docker-ready-blue.svg)](DEPLOY.md#docker-部署推荐)
将 DeepSeek 免费对话版转换为 **OpenAI & Claude 兼容 API**,支持多账号轮询、自动 Token 刷新、可视化管理界面。
![p1](https://github.com/user-attachments/assets/07296a50-50d4-4f05-a9e5-280df14e9532)
![p2](https://github.com/user-attachments/assets/03b4a763-766f-4050-aea8-1a183e70ae6a)
![p3](https://github.com/user-attachments/assets/beb9e41d-4c12-45d1-a26c-154280211185)
![p4](https://github.com/user-attachments/assets/fc8b9836-11e3-4c38-a684-eb2c79b80fe9)
![p5](https://github.com/user-attachments/assets/513e9ca7-aa9e-45a6-8f7e-f362b1650675)
## ✨ 特性
- 🔄 **双协议兼容** - 同时支持 OpenAI 和 Claude (Anthropic) API 格式
@@ -184,17 +193,26 @@ location / {
}
```
### Docker 部署(可选)
### 方式三:Docker 部署
```bash
# 使用环境变量配置
docker run -d \
-p 5001:5001 \
-e DS2API_ADMIN_KEY=your-admin-key \
-e DS2API_CONFIG_JSON='{"keys":["api-key"],"accounts":[...]}' \
ds2api
# 1. 克隆仓库并进入目录
git clone https://github.com/CJackHwang/ds2api.git
cd ds2api
# 2. 配置环境变量
cp .env.example .env
# 编辑 .env填写 DS2API_ADMIN_KEY 和 DS2API_CONFIG_JSON
# 3. 启动服务
docker-compose up -d
# 4. 查看日志
docker-compose logs -f
```
> **Docker 优势**:零侵入设计,主代码更新只需 `docker-compose up -d --build`,无需修改 Docker 配置。详见 [DEPLOY.md](DEPLOY.md#docker-部署推荐)。
## ⚠️ 免责声明
**本项目基于逆向工程实现,服务稳定性无法保证。**

32
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,32 @@
# DS2API 开发环境配置
# 特性:
# - 源代码挂载(热重载)
# - 调试日志级别
# - 自动重启
#
# 使用说明:
# docker-compose -f docker-compose.dev.yml up
services:
ds2api:
build: .
image: ds2api:dev
container_name: ds2api-dev
ports:
- "${PORT:-5001}:5001"
env_file:
- .env
environment:
- HOST=0.0.0.0
- LOG_LEVEL=DEBUG
volumes:
# 源代码挂载(开发时实时生效)
- ./app.py:/app/app.py:ro
- ./core:/app/core:ro
- ./routes:/app/routes:ro
- ./static:/app/static:ro
# 配置文件挂载(便于本地修改)
- ./config.json:/app/config.json:ro
restart: "no"
stdin_open: true
tty: true

29
docker-compose.yml Normal file
View File

@@ -0,0 +1,29 @@
# DS2API 生产环境配置
# 使用说明:
# 1. 复制 .env.example 为 .env 并填写配置
# 2. docker-compose up -d
# 3. 主代码更新后docker-compose up -d --build
#
# 设计原则:
# - 零侵入:所有项目配置通过 .env 文件传递
# - 易维护:主代码更新只需重新构建镜像
services:
ds2api:
build: .
image: ds2api:latest
container_name: ds2api
ports:
- "${PORT:-5001}:5001"
env_file:
- .env
environment:
# 确保容器内使用正确的主机绑定
- HOST=0.0.0.0
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5001/v1/models')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s

View File

@@ -299,3 +299,5 @@ async def webui(request: Request, path: str = ""):
return FileResponse(index_path)
return HTMLResponse(content="index.html not found", status_code=404)

View File

@@ -4,21 +4,9 @@
{
"src": "app.py",
"use": "@vercel/python"
},
{
"src": "static/**",
"use": "@vercel/static"
}
],
"routes": [
{
"src": "/admin/assets/(.*)",
"dest": "/static/admin/assets/$1"
},
{
"src": "/admin/(.+\\.[a-z]+)$",
"dest": "/static/admin/$1"
},
{
"src": "/(.*)",
"dest": "app.py"