增加部署配置

This commit is contained in:
yxj52 2025-08-30 09:57:30 +08:00
parent 37b159fb7e
commit 9e30335c37
11 changed files with 528 additions and 1 deletions

16
.dockerignore Normal file
View File

@ -0,0 +1,16 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
README.md
.env
.nyc_output
coverage
.DS_Store
.vscode
.idea
*.swp
*.swo
logs

9
.gitignore vendored
View File

@ -92,3 +92,12 @@ public
# Temporary folders
tmp/
temp/
# Docker
logs/
.docker/
# Database
*.db
*.sqlite
*.sqlite3

33
Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# 多阶段构建
# 第一阶段:构建阶段
FROM node:18-alpine as build-stage
# 设置工作目录
WORKDIR /app
# 复制package.json和package-lock.json
COPY package*.json ./
# 安装所有依赖(包括开发依赖用于构建)
RUN npm ci
# 复制源代码
COPY . .
# 构建应用
RUN npm run build
# 第二阶段:生产阶段
FROM nginx:alpine as production-stage
# 复制自定义nginx配置
COPY nginx.conf /etc/nginx/nginx.conf
# 从构建阶段复制构建结果到nginx
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 暴露端口
EXPOSE 80
# 启动nginx
CMD ["nginx", "-g", "daemon off;"]

123
QUICKSTART.md Normal file
View File

@ -0,0 +1,123 @@
# 🚀 快速开始指南
## 一键部署
使用以下命令即可快速部署办公智能编稿系统:
```bash
# 克隆项目如果是从Git仓库
git clone http://gitea.smartscf.cn:8000/yxj/office_intelligent_drafting.git
cd office_intelligent_drafting
# 运行一键部署脚本
./deploy.sh
```
## 手动部署步骤
### 1. 前置检查
确保你的系统已安装:
- Docker 20.0+
- Docker Compose 2.0+
```bash
docker --version
docker-compose --version
```
### 2. 部署应用
```bash
# 部署前端应用
docker-compose up --build -d
```
访问http://localhost:8080
### 3. 健康检查
```bash
# 检查所有服务状态
./healthcheck.sh
# 查看运行中的容器
docker-compose ps
# 查看日志
docker-compose logs -f
```
### 4. 停止服务
```bash
# 停止所有服务
docker-compose down
# 停止并删除数据卷
docker-compose down -v
```
## 常见问题
### Q: 端口被占用怎么办?
A: 修改 docker-compose.yml 中的端口映射:
```yaml
ports:
- "8081:80" # 改为其他端口
```
### Q: 如何查看详细错误?
A: 使用以下命令查看服务的日志:
```bash
docker-compose logs frontend
```
### Q: 如何重新构建?
A: 清理缓存并重新构建:
```bash
docker-compose down
docker-compose build --no-cache
docker-compose up -d
```
### Q: 数据如何持久化?
A: 日志自动保存在本地目录中:
- `./logs/nginx`: Nginx日志
## 开发模式
如果你想在开发模式下运行:
```bash
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
访问http://localhost:3000
## 生产部署建议
1. **安全配置**
- 修改默认密码
- 配置HTTPS
- 设置防火墙规则
2. **性能优化**
- 配置CDN
- 启用Gzip压缩
- 优化数据库索引
3. **监控告警**
- 配置日志收集
- 设置健康检查
- 监控资源使用
## 需要帮助?
- 查看完整文档README.md
- 提交问题GitHub Issues
- 联系维护者:[您的联系方式]

146
README.md
View File

@ -1,2 +1,146 @@
# office_intelligent_drafting
# 办公智能编稿系统 - Docker 部署指南
## 概述
本项目是一个基于Vue.js的办公智能编稿系统支持技术文档生成、办公助手、知识问答等功能。
## 功能特性
- 📝 技术文档生成器 - 支持多种文档类型和格式
- 🤖 办公助手 - 9个专业业务分析代理
- ❓ 知识问答 - 智能问答系统
- 🎯 办公代理 - 个性化办公助手
## Docker 部署
### 前置要求
- Docker 20.0+
- Docker Compose 2.0+
### 快速部署
#### 使用部署脚本(推荐)
```bash
# 运行部署脚本
./deploy.sh
```
#### 手动部署
```bash
# 构建并启动
docker-compose up --build -d
# 查看状态
docker-compose ps
```
### 访问应用
- 前端应用http://localhost:8080
### 常用命令
```bash
# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down
# 重启服务
docker-compose restart
# 清理(删除容器和卷)
docker-compose down -v
# 重新构建
docker-compose up --build
```
### 配置说明
#### 环境变量
可以在 `docker-compose.yml` 中修改以下环境变量:
- `NODE_ENV`: 运行环境 (production/development)
#### 端口配置
- 前端8080 → 80
#### 数据持久化
- Nginx日志`./logs/nginx` 目录
### 故障排除
1. **端口冲突**
```bash
# 修改 docker-compose.yml 中的端口映射
ports:
- "8081:80" # 改为其他端口
```
2. **权限问题**
```bash
# 确保有执行权限
chmod +x deploy.sh
```
3. **构建失败**
```bash
# 清理缓存重新构建
docker system prune -f
docker-compose build --no-cache
```
4. **查看详细日志**
```bash
# 查看前端服务日志
docker-compose logs frontend
```
### 开发环境
如果需要在开发环境中运行:
```bash
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
## 技术栈
- **前端**: Vue 3, Element Plus, Vue Router, ECharts
- **构建**: Vite
- **容器**: Docker, Docker Compose
- **Web服务器**: Nginx
## 项目结构
```
├── src/ # 源代码
│ ├── views/ # 页面组件
│ ├── components/ # 公共组件
│ └── router/ # 路由配置
├── Dockerfile # Docker镜像构建文件
├── docker-compose.yml # Docker部署配置
├── nginx.conf # Nginx配置
├── deploy.sh # 部署脚本
└── README.md # 说明文档
```
## 贡献
欢迎提交Issue和Pull Request来改进这个项目。
## 许可证
MIT License

41
deploy.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# 办公智能编稿系统 Docker 部署脚本
echo "🚀 开始部署办公智能编稿系统..."
# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
echo "❌ Docker 未安装,请先安装 Docker"
exit 1
fi
# 检查Docker Compose是否安装
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
echo "❌ Docker Compose 未安装,请先安装 Docker Compose"
exit 1
fi
# 创建日志目录
mkdir -p logs/nginx
echo "📦 准备部署前端应用..."
COMPOSE_FILE="docker-compose.yml"
# 停止现有容器
echo "🔄 停止现有容器..."
docker-compose -f $COMPOSE_FILE down
# 构建并启动容器
echo "🔨 构建并启动容器..."
docker-compose -f $COMPOSE_FILE up --build -d
# 检查容器状态
echo "✅ 检查容器状态..."
docker-compose -f $COMPOSE_FILE ps
echo ""
echo "🎉 部署完成!"
echo "📱 访问地址: http://localhost:12080"
echo "📋 查看日志: docker-compose -f $COMPOSE_FILE logs -f"
echo "🛑 停止服务: docker-compose -f $COMPOSE_FILE down"

20
docker-compose.simple.yml Normal file
View File

@ -0,0 +1,20 @@
version: '3.8'
services:
# 前端应用
frontend:
build:
context: .
dockerfile: Dockerfile
container_name: office-intelligent-drafting
ports:
- "12080:80"
restart: unless-stopped
environment:
- NODE_ENV=production
volumes:
- ./logs/nginx:/var/log/nginx
networks:
default:
driver: bridge

20
docker-compose.yml Normal file
View File

@ -0,0 +1,20 @@
version: '3.8'
services:
# 前端应用
frontend:
build:
context: .
dockerfile: Dockerfile
container_name: office-intelligent-drafting
ports:
- "12080:80"
restart: unless-stopped
environment:
- NODE_ENV=production
volumes:
- ./logs/nginx:/var/log/nginx
networks:
default:
driver: bridge

16
healthcheck.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# 健康检查脚本
echo "🔍 检查办公智能编稿系统健康状态..."
# 检查前端服务
echo "检查前端服务 (localhost:8080)..."
if curl -f http://localhost:8080 > /dev/null 2>&1; then
echo "✅ 前端服务正常"
else
echo "❌ 前端服务异常"
exit 1
fi
echo "🎉 健康检查完成!"

56
init.sql Normal file
View File

@ -0,0 +1,56 @@
-- 办公智能编稿系统数据库初始化脚本
-- 创建用户表
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 创建文档表
CREATE TABLE IF NOT EXISTS documents (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
title VARCHAR(200) NOT NULL,
content TEXT,
doc_type VARCHAR(50),
status VARCHAR(20) DEFAULT 'draft',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 创建知识库表
CREATE TABLE IF NOT EXISTS knowledge_base (
id SERIAL PRIMARY KEY,
title VARCHAR(200) NOT NULL,
content TEXT,
category VARCHAR(50),
tags TEXT[],
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 创建对话记录表
CREATE TABLE IF NOT EXISTS conversations (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
agent_type VARCHAR(50),
question TEXT,
answer TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 插入示例数据
INSERT INTO knowledge_base (title, content, category, tags) VALUES
('Vue.js 基础知识', 'Vue.js 是一个用于构建用户界面的渐进式框架...', '技术文档', ARRAY['Vue', 'JavaScript', '前端']),
('项目管理最佳实践', '有效的项目管理需要明确的目标设定...', '管理', ARRAY['项目管理', '团队协作']),
('数据分析方法论', '数据分析是从数据中提取有价值信息的过程...', '数据科学', ARRAY['数据分析', '统计学']);
-- 创建索引
CREATE INDEX IF NOT EXISTS idx_documents_user_id ON documents(user_id);
CREATE INDEX IF NOT EXISTS idx_documents_type ON documents(doc_type);
CREATE INDEX IF NOT EXISTS idx_conversations_user_id ON conversations(user_id);
CREATE INDEX IF NOT EXISTS idx_knowledge_category ON knowledge_base(category);

49
nginx.conf Normal file
View File

@ -0,0 +1,49 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# Vue Router 历史模式支持
location / {
try_files $uri $uri/ /index.html;
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}