Skip to content

Commit 8923ed1

Browse files
committed
feat: add dockefile and action
1 parent 5dbe1ec commit 8923ed1

File tree

7 files changed

+581
-15
lines changed

7 files changed

+581
-15
lines changed

.dockerignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Node modules
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Build outputs
8+
dist
9+
10+
# IDE files
11+
.vscode
12+
.idea
13+
*.swp
14+
*.swo
15+
16+
# OS generated files
17+
.DS_Store
18+
.DS_Store?
19+
._*
20+
.Spotlight-V100
21+
.Trashes
22+
ehthumbs.db
23+
Thumbs.db
24+
25+
# Git
26+
.git
27+
.gitignore
28+
29+
# Development files
30+
*.log
31+
.env
32+
.env.local
33+
.env.development.local
34+
.env.test.local
35+
.env.production.local
36+
37+
# Test files
38+
test
39+
tests
40+
*.test.js
41+
*.test.ts
42+
*.spec.js
43+
*.spec.ts
44+
45+
# Coverage reports
46+
coverage
47+
48+
# Docker files
49+
Dockerfile*
50+
docker-compose*
51+
52+
# Documentation (except README and LICENSE)
53+
docs
54+
*.md
55+
!README.md
56+
!LICENSE
57+
58+
# GitHub
59+
.github
60+
61+
# Other
62+
.nyc_output
63+
.eslintrc*
64+
.prettierrc*
65+
tsconfig.json

.github/workflows/docker-publish.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
15+
env:
16+
REGISTRY: docker.io
17+
IMAGE_NAME: zerob13/mock-openai-api
18+
19+
jobs:
20+
build-and-push:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to Docker Hub
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- name: Extract metadata
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
type=raw,value=latest,enable={{is_default_branch}}
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
platforms: linux/amd64,linux/arm64
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
65+
- name: Update Docker Hub description
66+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
67+
uses: peter-evans/dockerhub-description@v3
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
repository: ${{ env.IMAGE_NAME }}
72+
readme-filepath: ./README.md

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ dist
136136
.pnp.*
137137
package-lock.json
138138
pnpm-lock.yaml
139-
yarn.lock
139+
yarn.lock
140+
.DS_Store

DEPLOYMENT.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# 部署指南 / Deployment Guide
2+
3+
*[English](#english) | [中文](#中文)*
4+
5+
## 中文
6+
7+
### Docker Hub 自动部署
8+
9+
此项目已配置 GitHub Actions,会自动构建并推送 Docker 镜像到 Docker Hub。
10+
11+
#### 触发条件
12+
- 推送到 `main``master` 分支
13+
- 创建新的版本标签 (`v*`)
14+
- 提交 Pull Request(仅构建,不推送)
15+
16+
#### 镜像标签策略
17+
- `latest` - 最新的 main 分支构建
18+
- `v1.0.1` - 具体版本号
19+
- `1.0` - 主要版本号
20+
- `1` - 大版本号
21+
22+
### 使用预构建镜像
23+
24+
Docker Hub仓库:https://hub.docker.com/r/zerob13/mock-openai-api
25+
26+
```bash
27+
# 拉取最新镜像
28+
docker pull zerob13/mock-openai-api:latest
29+
30+
# 运行容器
31+
docker run -d -p 3000:3000 --name mock-openai-api zerob13/mock-openai-api:latest
32+
33+
# 检查健康状态
34+
curl http://localhost:3000/health
35+
```
36+
37+
### Docker Compose 部署
38+
39+
1. 下载 `docker-compose.yml` 文件
40+
2. 根据需要修改环境变量
41+
3. 启动服务:
42+
43+
```bash
44+
docker-compose up -d
45+
```
46+
47+
### 生产环境部署建议
48+
49+
#### 1. 使用具体版本标签
50+
```bash
51+
docker run -d -p 3000:3000 zerob13/mock-openai-api:v1.0.1
52+
```
53+
54+
#### 2. 配置反向代理(Nginx)
55+
```nginx
56+
server {
57+
listen 80;
58+
server_name your-domain.com;
59+
60+
location / {
61+
proxy_pass http://localhost:3000;
62+
proxy_set_header Host $host;
63+
proxy_set_header X-Real-IP $remote_addr;
64+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
65+
proxy_set_header X-Forwarded-Proto $scheme;
66+
67+
# 支持 Server-Sent Events
68+
proxy_buffering off;
69+
proxy_cache off;
70+
proxy_set_header Connection '';
71+
proxy_http_version 1.1;
72+
chunked_transfer_encoding off;
73+
}
74+
}
75+
```
76+
77+
#### 3. 设置资源限制
78+
```bash
79+
docker run -d \
80+
--name mock-openai-api \
81+
--restart unless-stopped \
82+
--memory="256m" \
83+
--cpus="0.5" \
84+
-p 3000:3000 \
85+
zerob13/mock-openai-api:latest
86+
```
87+
88+
### 环境变量配置
89+
90+
| 变量名 | 描述 | 默认值 |
91+
| ---------- | ------------ | ------------ |
92+
| `NODE_ENV` | Node.js 环境 | `production` |
93+
| `PORT` | 服务端口 | `3000` |
94+
| `HOST` | 绑定地址 | `0.0.0.0` |
95+
| `VERBOSE` | 详细日志 | `false` |
96+
| `TZ` | 时区设置 | `UTC` |
97+
98+
---
99+
100+
## English
101+
102+
### Automatic Docker Hub Deployment
103+
104+
This project is configured with GitHub Actions to automatically build and push Docker images to Docker Hub.
105+
106+
#### Trigger Conditions
107+
- Push to `main` or `master` branch
108+
- Create new version tags (`v*`)
109+
- Submit Pull Request (build only, no push)
110+
111+
#### Image Tagging Strategy
112+
- `latest` - Latest main branch build
113+
- `v1.0.1` - Specific version number
114+
- `1.0` - Major version number
115+
- `1` - Major version number
116+
117+
### Using Pre-built Images
118+
119+
Docker Hub Repository: https://hub.docker.com/r/zerob13/mock-openai-api
120+
121+
```bash
122+
# Pull latest image
123+
docker pull zerob13/mock-openai-api:latest
124+
125+
# Run container
126+
docker run -d -p 3000:3000 --name mock-openai-api zerob13/mock-openai-api:latest
127+
128+
# Check health status
129+
curl http://localhost:3000/health
130+
```
131+
132+
### Docker Compose Deployment
133+
134+
1. Download the `docker-compose.yml` file
135+
2. Modify environment variables as needed
136+
3. Start services:
137+
138+
```bash
139+
docker-compose up -d
140+
```
141+
142+
### Production Deployment Recommendations
143+
144+
#### 1. Use Specific Version Tags
145+
```bash
146+
docker run -d -p 3000:3000 zerob13/mock-openai-api:v1.0.1
147+
```
148+
149+
#### 2. Configure Reverse Proxy (Nginx)
150+
```nginx
151+
server {
152+
listen 80;
153+
server_name your-domain.com;
154+
155+
location / {
156+
proxy_pass http://localhost:3000;
157+
proxy_set_header Host $host;
158+
proxy_set_header X-Real-IP $remote_addr;
159+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
160+
proxy_set_header X-Forwarded-Proto $scheme;
161+
162+
# Support Server-Sent Events
163+
proxy_buffering off;
164+
proxy_cache off;
165+
proxy_set_header Connection '';
166+
proxy_http_version 1.1;
167+
chunked_transfer_encoding off;
168+
}
169+
}
170+
```
171+
172+
#### 3. Set Resource Limits
173+
```bash
174+
docker run -d \
175+
--name mock-openai-api \
176+
--restart unless-stopped \
177+
--memory="256m" \
178+
--cpus="0.5" \
179+
-p 3000:3000 \
180+
zerob13/mock-openai-api:latest
181+
```
182+
183+
### Environment Variables
184+
185+
| Variable | Description | Default |
186+
| ---------- | ------------------- | ------------ |
187+
| `NODE_ENV` | Node.js environment | `production` |
188+
| `PORT` | Server port | `3000` |
189+
| `HOST` | Bind address | `0.0.0.0` |
190+
| `VERBOSE` | Verbose logging | `false` |
191+
| `TZ` | Timezone setting | `UTC` |

0 commit comments

Comments
 (0)