feat: Docker化部署完成 - 前端管理后台和AI服务

- 添加 hzhub-admin Dockerfile (Nginx)
- 添加 hzhub-admin nginx.conf (API代理、SSE支持、Gzip)
- 添加 hzhub-ai Dockerfile (Spring Boot)
- 添加 hzhub-gateway Dockerfile
- 更新 docker-compose.yml 添加前端和AI服务
- 更新 README.md 完善部署文档
- 配置 application-dev.yml 数据库连接

所有服务现在可通过 docker-compose up -d 一键启动:
- hzhub-admin:5666 (管理后台)
- hzhub-ai:6039 (AI服务)
- mysql:3306, redis:6379, weaviate:28080, n8n:5678
This commit is contained in:
2026-03-27 06:04:58 +00:00
parent 3584e491cc
commit bc96a584fe
9 changed files with 280 additions and 100 deletions

View File

@@ -85,63 +85,107 @@ hzhub/
| 管理后台UI | Ant Design Vue (Vben Admin) |
| 门户UI | Element Plus X |
| 网关 | Spring Cloud Gateway |
| AI服务 | Spring Boot 3.x + Spring AI + LangChain4j |
| AI服务 | Spring Boot 3.5.8 + LangChain4j 1.11.0 |
| ERP服务 | Spring Boot 3.x + JDBC |
| 向量数据库 | Milvus |
| 关系数据库 | MySQL 8.0 + SQL Server 2008 R2 |
| 向量数据库 | Weaviate 1.25.0 |
| 关系数据库 | MySQL 8.0 |
| 缓存 | Redis 7 |
| 工作流 | n8n |
| 对象存储 | MinIO |
| 部署 | Docker Compose |
## 项目状态
- ✅ 基础设施 Docker 化 (MySQL, Redis, Weaviate, n8n, MinIO)
- ✅ AI服务 Docker 化 (hzhub-ai)
- ✅ 前端管理后台 Docker 化 (hzhub-admin)
- ⏳ ERP服务 (开发中)
- ⏳ API网关 (开发中)
- ⏳ 公司门户 (待配置)
- ⏳ 经销商门户 (待配置)
## 快速开始
### 环境准备
- JDK 17+
- Node.js 20+
- pnpm 9+
- Maven 3.8+
- Docker & Docker Compose
- JDK 17+ (本地开发)
- Node.js 22+ (本地开发)
- pnpm 10+ (本地开发)
- Maven 3.9+ (本地开发)
### 启动基础设施
### 一键启动Docker Compose
```bash
cd hzhub-deploy
docker-compose up -d
```
### 启动后端服务
启动完成后访问:
- 🌐 管理后台: http://localhost:5666
- 🔧 AI服务API: http://localhost:6039
- 🔄 n8n工作流: http://localhost:5678
### 服务清单
| 服务名 | 容器名 | 端口 | 说明 |
|--------|--------|------|------|
| hzhub-admin | hzhub-deploy-hzhub-admin | 5666 | 管理后台前端(Nginx) |
| hzhub-ai | hzhub-deploy-hzhub-ai | 6039 | AI后端服务(Spring Boot) |
| mysql | hzhub-mysql | 3306 | MySQL 8.0数据库 |
| redis | hzhub-redis | 6379 | Redis 7缓存 |
| weaviate | hzhub-weaviate | 28080 | Weaviate向量数据库 |
| n8n | hzhub-n8n | 5678 | n8n工作流引擎 |
| minio | hzhub-deploy-minio-1 | 9000 | MinIO对象存储 |
| etcd | hzhub-deploy-etcd-1 | 2379 | etcd服务发现 |
### 本地开发启动
#### 后端服务
```bash
# AI服务
cd hzhub-ai/ruoyi-admin
mvn spring-boot:run
# ERP服务
cd hzhub-erp
mvn spring-boot:run
# 网关服务
cd hzhub-gateway
mvn spring-boot:run
mvn spring-boot:run -Dspring-boot.run.profiles=dev
```
### 启动前端
#### 前端开发
```bash
# 管理后台
cd hzhub-admin
pnpm install
pnpm dev
```
# 公司门户
cd hzhub-portal-company
pnpm install
pnpm dev
#### 前端生产构建
# 经销商门户
cd hzhub-portal-dealer
pnpm install
pnpm dev
```bash
cd hzhub-admin
# 先构建依赖包
pnpm build
# 再构建前端
pnpm --filter=@vben/web-antd build:prod
```
### 常用命令
```bash
# 查看所有服务状态
docker-compose ps
# 查看服务日志
docker-compose logs -f hzhub-ai
docker-compose logs -f hzhub-admin
# 重启服务
docker-compose restart hzhub-ai
# 停止所有服务
docker-compose down
# 停止并删除数据卷(谨慎使用)
docker-compose down -v
```
## 文档

14
hzhub-admin/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
# 使用 Nginx 托管已构建的前端
FROM nginx:alpine
# 复制构建产物到 Nginx 目录
COPY apps/web-antd/dist /usr/share/nginx/html
# 复制 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 暴露端口
EXPOSE 5666
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]

54
hzhub-admin/nginx.conf Normal file
View File

@@ -0,0 +1,54 @@
server {
listen 5666;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# API 代理到后端服务
location /api/ {
proxy_pass http://hzhub-ai:6039/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 86400;
}
# SSE 支持
location /api/sse/ {
proxy_pass http://hzhub-ai:6039/sse/;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 86400;
}
# 前端路由支持 - 所有路径指向 index.html
location / {
try_files $uri $uri/ /index.html;
}
# 健康检查
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}

28
hzhub-ai/Dockerfile Normal file
View File

@@ -0,0 +1,28 @@
# 构建阶段
FROM maven:3.9-eclipse-temurin-17-alpine AS builder
WORKDIR /app
# 复制pom文件和源码
COPY pom.xml .
COPY ruoyi-admin ./ruoyi-admin
COPY ruoyi-common ./ruoyi-common
COPY ruoyi-extend ./ruoyi-extend
COPY ruoyi-modules ./ruoyi-modules
# 构建项目(跳过测试)
RUN mvn clean package -DskipTests -pl ruoyi-admin -am
# 运行阶段
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
# 复制构建产物
COPY --from=builder /app/ruoyi-admin/target/ruoyi-admin.jar app.jar
# 暴露端口
EXPOSE 6039
# 启动命令
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -58,9 +58,9 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:mysql://127.0.0.1:3306/ruoyi-ai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://127.0.0.1:3306/ruoyi_ai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: root
password: hzhub123
# agent:
# url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# # url: jdbc:mysql://localhost:3306/agent_db

View File

@@ -14,6 +14,11 @@ services:
- mysql_data:/var/lib/mysql
networks:
- hzhub-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-hzhub123}"]
interval: 10s
timeout: 5s
retries: 5
# Redis
redis:
@@ -25,42 +30,50 @@ services:
- redis_data:/data
networks:
- hzhub-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
# Milvus (向量数据库)
milvus-standalone:
image: milvusdb/milvus:v2.4.5
container_name: hzhub-milvus
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
# Weaviate (向量数据库)
weaviate:
image: semitechnologies/weaviate:1.25.0
container_name: hzhub-weaviate
ports:
- "19530:19530"
- "9091:9091"
- "28080:8080"
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
DEFAULT_VECTORIZER_MODULE: 'none'
ENABLE_MODULES: ''
CLUSTER_HOSTNAME: 'node1'
volumes:
- weaviate_data:/var/lib/weaviate
networks:
- hzhub-network
# hzhub-ai (AI服务)
hzhub-ai:
build:
context: ../hzhub-ai
dockerfile: Dockerfile
container_name: hzhub-ai
ports:
- "6039:6039"
environment:
SPRING_PROFILES_ACTIVE: dev
SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_URL: jdbc:mysql://hzhub-mysql:3306/ruoyi_ai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_USERNAME: root
SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_PASSWORD: hzhub123
SPRING_DATA_REDIS_HOST: hzhub-redis
SPRING_DATA_REDIS_PORT: 6379
depends_on:
- etcd
- minio
etcd:
image: quay.io/coreos/etcd:v3.5.5
environment:
- ETCD_AUTO_COMPACTION_MODE=revision
- ETCD_AUTO_COMPACTION_RETENTION=1000
- ETCD_QUOTA_BACKEND_BYTES=4294967296
volumes:
- etcd_data:/etcd
networks:
- hzhub-network
minio:
image: minio/minio:latest
environment:
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-minioadmin}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin}
volumes:
- minio_data:/minio_data
command: minio server /minio_data
mysql:
condition: service_healthy
redis:
condition: service_healthy
networks:
- hzhub-network
@@ -79,11 +92,25 @@ services:
networks:
- hzhub-network
# hzhub-admin (前端管理后台)
hzhub-admin:
build:
context: ../hzhub-admin
dockerfile: Dockerfile
container_name: hzhub-admin
ports:
- "5666:5666"
environment:
- NGINX_PORT=5666
depends_on:
- hzhub-ai
networks:
- hzhub-network
volumes:
mysql_data:
redis_data:
etcd_data:
minio_data:
weaviate_data:
n8n_data:
networks:

9
hzhub-gateway/Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY target/hzhub-gateway.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -22,55 +22,17 @@
<properties>
<java.version>17</java.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>
<sa-token.version>1.44.0</sa-token.version>
</properties>
<dependencies>
<!-- Spring Cloud Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- Spring Cloud LoadBalancer -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- Sa-Token -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-reactor-spring-boot3-starter</artifactId>
<version>${sa-token.version}</version>
</dependency>
<!-- Sa-Token Redis -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
<version>${sa-token.version}</version>
</dependency>
<!-- Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>

42
lefthook.yml Normal file
View File

@@ -0,0 +1,42 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://lefthook.dev/configuration/
#
# pre-push:
# jobs:
# - name: packages audit
# tags:
# - frontend
# - security
# run: yarn audit
#
# - name: gems audit
# tags:
# - backend
# - security
# run: bundle audit
#
# pre-commit:
# parallel: true
# jobs:
# - run: yarn eslint {staged_files}
# glob: "*.{js,ts,jsx,tsx}"
#
# - name: rubocop
# glob: "*.rb"
# exclude:
# - config/application.rb
# - config/routes.rb
# run: bundle exec rubocop --force-exclusion {all_files}
#
# - name: govet
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
#
# - script: "hello.js"
# runner: node
#
# - script: "hello.go"
# runner: go run