Files
ocdp-go/backend
Ivan087 985369d40f fix: resolve deployment API errors and enable E2E deployment flow
Backend fixes:
- instance_dto: add Version field with Normalize() to support both 'version'
  and 'tag' field names from frontend
- instance_handler: add version empty validation before creating instance
- authz.go: fix unused variable compilation error
- registry_repository: fix GetByID/GetByName to use correct DB schema
  (add workspace_id, owner_id, is_shared fields); decrypt password
  gracefully when encryption key mismatches instead of returning error

Frontend:
- charts/page: add Template and Storage dropdown selectors to Deploy Modal

Testing:
- add e2e_test.py: 5-step Playwright E2E test (admin login → create
  workspace → create user → user login → deploy chart)
- add tasks/lesson.md: document 4 bug root causes and fixes
- add tasks/todo.md: track implementation progress
- add PLAN_E2E_DEPLOYMENT.md: comprehensive implementation plan

Verification: confirmed deployment creates instance with status=deployed,
chart downloads from Harbor OCI to /tmp/charts/, Helm release deploys to K8s
2026-04-16 18:39:23 +08:00
..
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00
2025-11-13 02:54:06 +00:00

OCDP Backend

Go 后端服务,提供 Kubernetes Helm Chart 部署能力。

技术栈

  • Go 1.21+
  • gorilla/mux (HTTP 路由)
  • ORAS Go SDK v2 (OCI 操作)
  • Helm SDK (Helm 操作)
  • Kubernetes client-go
  • PostgreSQL

启动

# Mock 模式(无需数据库,无需外部服务)
ADAPTER_MODE=mock go run cmd/api/main.go

# 生产模式(需要 PostgreSQL + K8s/Harbor 连接验证)
# 启动 PostgreSQL
docker compose up -d postgres

# 启动后端(生产模式)
cd backend
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/ocdp?sslmode=disable"
export JWT_SECRET="your-jwt-secret"
export ENCRYPTION_KEY="your-32-byte-encryption-key"
export PORT=8081
export ADAPTER_MODE=production
export KUBECONFIG=/home/ivanwu/.kube/config  # 或你的 kubeconfig 路径

# Harbor 凭证(可选,用于验证 Registry 连接)
export HARBOR_URL="https://harbor.bwgdi.com"
export HARBOR_USERNAME="your-harbor-user"
export HARBOR_PASSWORD="your-harbor-password"

# NFS 配置(可选)
export NFS_SERVER="10.6.80.11"
export NFS_SHARE="/volume1/NFS"

go run cmd/api/main.go

环境变量说明

变量 必需 说明
DATABASE_URL PostgreSQL 连接字符串
JWT_SECRET JWT 签名密钥
ENCRYPTION_KEY 32位加密密钥
PORT 服务端口,默认 8080
ADAPTER_MODE mockproduction,默认 production
KUBECONFIG 生产模式 Kubernetes kubeconfig 文件路径
HARBOR_URL Harbor URL用于 Registry 验证
HARBOR_USERNAME Harbor 用户名
HARBOR_PASSWORD Harbor 密码

连接验证

在生产模式下,创建 Cluster 或 Registry 时会自动验证连接:

  • Cluster: 尝试使用提供的凭证连接 K8s API Server
  • Registry: 尝试使用提供的凭证登录 Harbor

如果验证失败,创建会返回错误信息。

API 访问

项目结构

backend/
├── cmd/api/               # 入口
├── internal/
│   ├── domain/            # 领域层
│   │   ├── entity/        # 实体
│   │   ├── service/       # 业务逻辑
│   │   └── repository/    # 接口
│   ├── adapter/
│   │   ├── input/http/    # REST API
│   │   └── output/        # 数据库、OCI、Helm
│   └── bootstrap/         # 启动配置
└── docs/                  # OpenAPI 规范