feat: 添加Docker支持,支持容器化部署
This commit is contained in:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
.env
|
||||||
|
.git
|
||||||
|
database/app.db
|
||||||
|
token.json
|
||||||
|
plans/
|
||||||
|
UI.md
|
||||||
|
screenshots/
|
||||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# 使用 Node.js 18 LTS 版本
|
||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制 package.json 和 package-lock.json
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
RUN npm ci --only=production
|
||||||
|
|
||||||
|
# 复制项目文件
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 创建数据库目录
|
||||||
|
RUN mkdir -p database
|
||||||
|
|
||||||
|
# 暴露端口
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# 启动命令
|
||||||
|
CMD ["npm", "start"]
|
||||||
28
README.md
28
README.md
@@ -53,14 +53,34 @@
|
|||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
### 1. 安装依赖
|
### 方式一:Docker 部署(推荐)
|
||||||
|
|
||||||
|
使用 Docker Compose 一键部署:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 克隆项目
|
||||||
|
git clone https://github.com/lulistart/gpt2api-node.git
|
||||||
|
cd gpt2api-node
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
docker-compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
服务将在 `http://localhost:3000` 启动。
|
||||||
|
|
||||||
|
### 方式二:本地部署
|
||||||
|
|
||||||
|
#### 1. 安装依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd gpt2api-node
|
cd gpt2api-node
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. 初始化数据库
|
#### 2. 初始化数据库
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run init-db
|
npm run init-db
|
||||||
@@ -70,7 +90,7 @@ npm run init-db
|
|||||||
- 用户名:`admin`
|
- 用户名:`admin`
|
||||||
- 密码:`admin123`
|
- 密码:`admin123`
|
||||||
|
|
||||||
### 3. 启动服务
|
#### 3. 启动服务
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm start
|
npm start
|
||||||
@@ -82,7 +102,7 @@ npm start
|
|||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. 访问管理后台
|
#### 4. 访问管理后台
|
||||||
|
|
||||||
打开浏览器访问:`http://localhost:3000/admin`
|
打开浏览器访问:`http://localhost:3000/admin`
|
||||||
|
|
||||||
|
|||||||
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
gpt2api:
|
||||||
|
build: .
|
||||||
|
container_name: gpt2api-node
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
volumes:
|
||||||
|
- ./database:/app/database
|
||||||
|
- ./models.json:/app/models.json
|
||||||
|
environment:
|
||||||
|
- PORT=3000
|
||||||
|
- LOAD_BALANCE_STRATEGY=round-robin
|
||||||
|
- SESSION_SECRET=${SESSION_SECRET:-change-this-secret-in-production}
|
||||||
|
command: sh -c "npm run init-db && npm start"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
Reference in New Issue
Block a user