基于Docker容器化技术的电商数据管理系统,包含前端服务、后端API服务、数据库服务,以及完整的CI/CD流水线。
┌─────────────────────────────────────────────────────────────────┐
│ 用户访问层 │
│ http://localhost:80 │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Frontend (Nginx + Vue) │
│ Container: frontend │
│ Port: 80 │
└─────────────────────────────────────────────────────────────────┘
│
│ /api/*
▼
┌─────────────────────────────────────────────────────────────────┐
│ Backend (Spring Boot API) │
│ Container: backend │
│ Port: 8080 │
└─────────────────────────────────────────────────────────────────┘
│
│ JDBC
▼
┌─────────────────────────────────────────────────────────────────┐
│ MySQL Database │
│ Container: mysql │
│ Port: 3306 │
└─────────────────────────────────────────────────────────────────┘
| 组件 | 技术 | 版本 |
|---|---|---|
| 前端 | Vue 3 + Element Plus | 3.3.x |
| 后端 | Spring Boot | 3.2.x |
| 数据库 | MySQL | 8.0 |
| 容器化 | Docker + Docker Compose | 24.x |
| CI/CD | GitLab CI | - |
| 容器编排 | Kubernetes (Minikube) | 1.28.x |
| 监控 | Prometheus + Grafana | - |
- Docker 24.0+
- Docker Compose 2.20+
- Git
# 克隆项目
git clone <repository-url>
cd ecommerce-docker
# 复制环境变量配置
cp .env.example .env
# 启动所有服务
docker-compose up -d
# 查看服务状态
docker-compose ps- 前端页面: http://localhost:80
- 后端API: http://localhost:8080/api/products
- 健康检查: http://localhost:8080/health
ecommerce-docker/
├── backend/ # 后端服务
│ ├── src/
│ │ ├── main/java/com/ecommerce/
│ │ │ ├── controller/ # REST控制器
│ │ │ ├── service/ # 业务逻辑
│ │ │ ├── repository/ # 数据访问
│ │ │ ├── entity/ # 实体类
│ │ │ └── config/ # 配置类
│ │ └── resources/
│ │ └── application.yml
│ ├── Dockerfile
│ └── pom.xml
├── frontend/ # 前端服务
│ ├── src/
│ │ ├── views/ # 页面组件
│ │ ├── api/ # API调用
│ │ └── router/ # 路由配置
│ ├── nginx/ # Nginx配置
│ ├── Dockerfile
│ └── package.json
├── database/ # 数据库
│ ├── init/ # 初始化脚本
│ └── my.cnf # MySQL配置
├── k8s/ # Kubernetes配置
│ ├── base/ # 基础部署
│ └── blue-green/ # 蓝绿部署
├── monitoring/ # 监控配置
│ ├── prometheus/
│ └── grafana/
├── docs/ # 文档
├── docker-compose.yml
├── .gitlab-ci.yml
└── README.md
| 方法 | 路径 | 描述 |
|---|---|---|
| GET | /api/products | 获取商品列表(分页) |
| GET | /api/products/{id} | 获取商品详情 |
| POST | /api/products | 创建商品 |
| PUT | /api/products/{id} | 更新商品 |
| DELETE | /api/products/{id} | 删除商品 |
| GET | /api/products/search | 搜索商品 |
| GET | /api/products/categories | 获取所有分类 |
# 获取商品列表
curl http://localhost:8080/api/products
# 创建商品
curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "iPhone 15",
"description": "Apple新款手机",
"price": 8999.00,
"stock": 100,
"category": "手机数码"
}'# 后端单元测试
cd backend
mvn test
# 查看测试覆盖率报告
mvn jacoco:report
# 报告位置: target/site/jacoco/index.html
# 前端测试
cd frontend
npm test# 启动Minikube
minikube start
# 部署应用
kubectl apply -f k8s/base/
# 查看部署状态
kubectl get pods -n ecommerce
# 蓝绿部署
kubectl apply -f k8s/blue-green/
./k8s/blue-green/switch-traffic.sh green# 启动监控服务
docker-compose -f monitoring/docker-compose.monitoring.yml up -d
# 访问
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (admin/admin123)胡鑫煜 - 独立完成全部开发工作
MIT License