Add new frontend pages for the multi-tenant OCDP platform: - Charts page (/charts): Browse Harbor OCI registries to list Helm chart repositories and versions, with deploy modal to launch charts on selected clusters - Monitoring page (/monitoring): Display cluster metrics (CPU/Memory/GPU usage) and per-node details with resource utilization bars - Chart References page (/chart-references): CRUD for chart metadata references - Values Templates page (/templates): CRUD for Helm values templates with version history and rollback support - Sidebar: Add Charts navigation, update Storage and Templates links - api.ts: Add all API client functions (clusterApi, registryApi, instanceApi, monitoringApi, storageApi, chartReferenceApi, valuesTemplateApi, workspaceApi, userApi) with full TypeScript types Note: deploy flow and values template rollback not yet end-to-end tested.
201 lines
6.3 KiB
Markdown
201 lines
6.3 KiB
Markdown
# OCDP - Open Cloud Deployment Platform
|
||
|
||
开源云原生部署平台,支持从 Harbor(或其他 OCI Registry)拉取 Helm Charts 并一键部署到多个 Kubernetes 集群。
|
||
|
||
## 功能特性
|
||
|
||
- **多集群管理** - 支持多个 kubeconfig,管理多个 K8S 集群
|
||
- **Registry 管理** - 支持 Harbor、Docker Registry、OCI 标准仓库
|
||
- **多租户支持** - Workspace 隔离,管理员和普通用户角色
|
||
- **存储后端** - NFS/PV/hostPath 存储配置管理
|
||
- **Chart 引用** - 管理可用的 Helm Charts
|
||
- **Values 模板** - 版本控制、支持回滚的配置模板
|
||
- **一键部署** - 从 Harbor 拉取 Charts 部署到指定集群
|
||
- **实例管理** - 支持升级、回滚、卸载 Helm Release
|
||
- **状态监控** - 实时同步 Helm Release 状态
|
||
|
||
## 技术栈
|
||
|
||
| 层级 | 技术 |
|
||
|------|------|
|
||
| 后端 | Go 1.21+, Hexagonal Architecture |
|
||
| 前端 | React 18, TypeScript, Next.js, TailwindCSS |
|
||
| 数据库 | PostgreSQL |
|
||
| 网关 | Nginx |
|
||
|
||
## 快速开始
|
||
|
||
### Docker Compose 启动(推荐)
|
||
|
||
```bash
|
||
# 1. 完全停止并清理现有容器
|
||
docker compose -f docker-compose.yml -f backend/docker-compose.yml down -v
|
||
|
||
# 2. 启动所有服务(PostgreSQL + Backend + Frontend + Nginx)
|
||
ALLOWED_DEV_ORIGINS="http://10.6.80.114:3000" \
|
||
NEXT_PUBLIC_API_URL="http://10.6.80.114:8080/api/v1" \
|
||
BACKEND_PORT=8080 \
|
||
docker compose -f docker-compose.yml -f backend/docker-compose.yml --profile backend up -d
|
||
|
||
# 3. 查看服务状态
|
||
docker ps
|
||
|
||
# 4. 访问
|
||
# 前端: http://10.6.80.114
|
||
# 后端: http://10.6.80.114:8080/api/v1
|
||
# 默认账号: admin / admin123
|
||
|
||
# 停止服务
|
||
docker compose -f docker-compose.yml -f backend/docker-compose.yml down
|
||
```
|
||
|
||
### 开发环境
|
||
|
||
```bash
|
||
# 1. 确保 PostgreSQL 运行在 localhost:5432
|
||
# 启动 PostgreSQL 容器:
|
||
# docker run -d --name ocdp-postgres -e POSTGRES_DB=ocdp -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:15
|
||
|
||
# 2. 初始化数据库(首次运行)
|
||
# 方法一:手动执行 SQL
|
||
cat backend/scripts/init-db.sql | docker exec -i ocdp-postgres psql -U postgres -d ocdp
|
||
|
||
# 方法二:使用 Make(需确保 PostgreSQL 容器名为 ocdp-postgres)
|
||
make db-init
|
||
|
||
# 3. 启动后端(需要设置环境变量)
|
||
cd backend && \
|
||
DATABASE_URL="postgres://postgres:postgres@localhost:5432/ocdp?sslmode=disable" \
|
||
JWT_SECRET="test-jwt-secret-key" \
|
||
ENCRYPTION_KEY="test-encryption-key-32-bytes-long" \
|
||
PORT=8081 \
|
||
ALLOWED_DEV_ORIGINS="10.6.80.114,localhost,127.0.0.1" \
|
||
go run cmd/api/main.go
|
||
|
||
# 4. 启动前端(需要 Node.js 20)
|
||
source ~/.nvm/nvm.sh && nvm use 20
|
||
cd frontend && NEXT_PUBLIC_API_URL=http://10.6.80.114:8081/api/v1 npm run dev
|
||
|
||
# 5. 从外部访问
|
||
# 本机访问: http://localhost:3000
|
||
# 外部访问: http://10.6.80.114:3000
|
||
# 默认账号: admin / admin123
|
||
|
||
# ===== 一键启动脚本 =====
|
||
# 启动所有服务(后台运行)
|
||
./start.sh
|
||
|
||
# 停止所有服务
|
||
./stop.sh
|
||
```
|
||
|
||
### 生产环境(Docker Compose)
|
||
|
||
```bash
|
||
# 构建并启动所有服务
|
||
make run-2
|
||
|
||
# 停止服务
|
||
make clean-2
|
||
```
|
||
|
||
## 配置
|
||
|
||
### 环境变量
|
||
|
||
| 变量 | 默认值 | 说明 |
|
||
|------|--------|------|
|
||
| DATABASE_URL | postgres://postgres:postgres@localhost:5432/ocdp?sslmode=disable | 数据库连接串 |
|
||
| PORT | 8080 | 后端端口 |
|
||
| BACKEND_PORT | 8080 | Docker 映射端口 |
|
||
| JWT_SECRET | change-me-in-production | JWT 密钥 |
|
||
| ENCRYPTION_KEY | change-me-32-bytes-long-key-here | 加密密钥 |
|
||
| ALLOWED_DEV_ORIGINS | http://10.6.80.114:3000 | 允许的跨域来源(外部访问时需要配置)|
|
||
| NEXT_PUBLIC_API_URL | http://10.6.80.114:8080/api/v1 | 前端调用的API地址 |
|
||
|
||
### 配置文件
|
||
|
||
项目根目录 `.env` 文件包含默认配置:
|
||
- Kubernetes 集群配置
|
||
- Harbor 仓库信息
|
||
- NFS 存储配置
|
||
|
||
## 访问
|
||
|
||
| 服务 | 地址 |
|
||
|------|------|
|
||
| 前端 (Nginx) | http://10.6.80.114 |
|
||
| 后端 API | http://10.6.80.114:8080/api/v1 |
|
||
| API 文档 | http://10.6.80.114:8080/api/docs |
|
||
|
||
**默认账号**: `admin` / `admin123`
|
||
|
||
## 项目结构
|
||
|
||
```
|
||
ocdp-go/
|
||
├── backend/ # Go 后端 (Hexagonal Architecture)
|
||
│ ├── cmd/api/ # 入口点
|
||
│ ├── internal/
|
||
│ │ ├── adapter/ # 适配器层 (HTTP, Persistence)
|
||
│ │ ├── domain/ # 领域层 (Entity, Service, Repository)
|
||
│ │ └── bootstrap/ # 初始化和种子数据
|
||
│ └── scripts/ # 脚本 (init-db.sql)
|
||
├── frontend/ # Next.js 前端
|
||
│ ├── src/
|
||
│ │ ├── app/ # 页面路由
|
||
│ │ ├── components/ # 组件
|
||
│ │ └── lib/ # 工具库 (API, types, auth)
|
||
│ └── .env.local # 前端环境配置
|
||
├── infra/nginx/ # Nginx 配置
|
||
├── docker-compose.yml # 主配置
|
||
├── backend/docker-compose.yml # 后端配置
|
||
└── Makefile # 构建命令
|
||
```
|
||
|
||
## 核心 API
|
||
|
||
| 模块 | 端点 | 说明 |
|
||
|------|------|------|
|
||
| 认证 | POST /api/v1/auth/login | 用户登录 |
|
||
| 用户 | GET/POST /api/v1/users | 用户管理 |
|
||
| Workspaces | GET/POST /api/v1/workspaces | 工作空间管理 |
|
||
| Clusters | GET/POST /api/v1/clusters | 集群管理 |
|
||
| Registries | GET/POST /api/v1/registries | 镜像仓库管理 |
|
||
| Storage | GET/POST /api/v1/storage-backends | 存储后端管理 |
|
||
| Chart References | GET/POST /api/v1/chart-references | Chart 引用管理 |
|
||
| Values Templates | GET/POST /api/v1/values-templates | 配置模板管理 |
|
||
| Instances | GET/POST/DELETE /api/v1/instances | 实例部署管理 |
|
||
|
||
## 权限模型
|
||
|
||
- **Admin** - 管理员,可管理所有资源和用户
|
||
- **User** - 普通用户,仅可访问所属 Workspace 的资源
|
||
|
||
## 开发命令
|
||
|
||
```bash
|
||
# 启动开发服务器
|
||
make dev # 同时启动前后端
|
||
make dev-backend # 仅后端
|
||
make dev-frontend # 仅前端
|
||
|
||
# 数据库操作
|
||
make db-init # 初始化数据库
|
||
make db-reset # 重置数据库
|
||
make db-shell # 打开数据库 shell
|
||
|
||
# Docker 构建
|
||
make build # 构建所有镜像
|
||
make build-backend # 构建后端镜像
|
||
make build-frontend # 构建前端镜像
|
||
|
||
# 日志和调试
|
||
make logs # 查看所有日志
|
||
make logs-backend # 后端日志
|
||
make stop # 停止开发服务器
|
||
```
|
||
|
||
## License
|
||
|
||
MIT |