Skip to content

Commit 26ae3e3

Browse files
Merge pull request #3 from zhongruan0522/master
推送Docker部署方法
2 parents 47c2776 + 9c7a0fd commit 26ae3e3

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed

.github/workflows/docker.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- beta
7+
- master
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest # 使用最便宜的Linux runner
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Log in to Container Registry
28+
if: github.event_name != 'pull_request'
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=sha,prefix={{branch}}-
44+
type=raw,value=latest,enable={{is_default_branch}}
45+
46+
- name: Build and push Docker image
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
push: ${{ github.event_name != 'pull_request' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
55+
platforms: linux/amd64 # 只构建amd64镜像节省成本

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ Thumbs.db
4646
legacy
4747
config.yaml
4848

49+
.spec-workflow/

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 使用官方Python运行时作为基础镜像
2+
FROM python:3.11-slim
3+
4+
# 设置工作目录
5+
WORKDIR /app
6+
7+
# 复制requirements文件并安装依赖
8+
COPY requirements.txt .
9+
RUN pip install --no-cache-dir -r requirements.txt
10+
11+
# 复制应用代码
12+
COPY . .
13+
14+
# 创建非root用户
15+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
16+
USER appuser
17+
18+
# 暴露端口
19+
EXPOSE 8000
20+
21+
# 健康检查
22+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
23+
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
24+
25+
# 启动命令
26+
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,62 @@ model:
5555
5656
### 3. 运行服务
5757
58+
#### 本地部署
59+
5860
```bash
5961
python main.py
6062
```
6163

64+
#### Docker 部署
65+
66+
##### 使用 Docker Compose(推荐)
67+
68+
```bash
69+
# 使用GitHub镜像运行
70+
docker-compose up -d
71+
72+
# 查看日志
73+
docker-compose logs -f
74+
75+
# 停止服务
76+
docker-compose down
77+
```
78+
79+
##### 使用 Docker 直接运行
80+
81+
```bash
82+
# 使用GitHub镜像直接运行
83+
docker run -d \
84+
--name deepapi \
85+
-p 8000:8000 \
86+
-v $(pwd)/config.yaml:/app/config.yaml:ro \
87+
ghcr.io/zhongruan0522/deepapi:latest
88+
89+
# 如果需要本地构建
90+
docker build -t deepapi .
91+
docker run -d \
92+
--name deepapi \
93+
-p 8000:8000 \
94+
-v $(pwd)/config.yaml:/app/config.yaml:ro \
95+
deepapi
96+
```
97+
98+
##### 环境变量说明
99+
- `PYTHONUNBUFFERED=1`: 启用Python日志输出
100+
- 自定义DNS服务器(解决网络问题):`8.8.8.8`, `8.8.4.4`
101+
102+
##### 健康检查
103+
容器包含健康检查,可通过以下命令查看状态:
104+
```bash
105+
docker ps --format "table {{.Names}}\t{{.Status}}"
106+
```
107+
108+
##### 生产环境建议
109+
1. 使用稳定版本镜像标签(如 `beta` 或具体版本号),避免使用 `latest`
110+
2. 设置适当的资源限制
111+
3. 配置日志收集
112+
4. 使用HTTPS和适当的认证
113+
62114
## API 使用
63115

64116
### 聊天补全
@@ -218,4 +270,8 @@ models:
218270
Agent N: 角度N ──┘
219271
220272
综合所有结果 → 输出最佳方案
221-
```
273+
```
274+
275+
## 架构说明
276+
277+
### DeepThink 流程

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.8'
2+
3+
services:
4+
deepapi:
5+
image: ghcr.io/zhongruan0522/deepapi:beta
6+
container_name: deepapi
7+
ports:
8+
- "8000:8000"
9+
volumes:
10+
- ./config.yaml:/app/config.yaml:ro
11+
environment:
12+
- PYTHONUNBUFFERED=1
13+
dns:
14+
- 8.8.8.8
15+
- 8.8.4.4
16+
restart: unless-stopped
17+
healthcheck:
18+
test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:8000/health')"]
19+
interval: 30s
20+
timeout: 10s
21+
retries: 3
22+
start_period: 40s

0 commit comments

Comments
 (0)