feat: 去 mock 化 —— 全模块接入真实数据 (参考 jianmu/opsx-jenkins/aiops)

后端(35+ 新路由):
- AES-256-GCM 字段加密(enc:v1:),密钥自动生成 data/encryption.key
- 新模型:Host/K8sCluster/Credential/BuildNode/DeployTool/WebhookEndpoint/
  JenkinsServer/SystemSetting;Pipeline 扩展触发器/变量/缓存列,
  PipelineRun 扩展 buildNumber/externalUrl
- 资源 CRUD + 真实测试端点:主机/集群/构建节点 TCP 拨号、
  工具真实执行版本检测(保守安装策略)、Webhook HMAC-SHA256 签名发送、
  入站流水线触发 /api/hooks/pipeline/:id
- Jenkins 完整集成(移植 opsx-jenkins 生产客户端):crumb/BasicAuth/
  buildWithParameters/Location 队列/progressiveText 增量控制台,
  服务器 CRUD+测试、Job 树拉取(folder 压平)、导入为流水线、
  jenkins 类型流水线真实执行回传日志
- 流水线列表附带 lastRun、运行重试、summary 统计、系统设置单行表
- 运行结束触发出站 Webhook 通知;GitOps 同步状态真实推进

前端(14 页全部去 mock):
- 流水线列表/发布记录/批量发布/环境/凭证/构建节点/工具/Webhook/
  系统设置/Jenkins 导入/GitOps(资源树+差异) 全部接入真实 API
- 编辑器 4 Tab 持久化(基本信息/触发设置含真实 Webhook URL/变量缓存/发布历史)
- TopBar 真实流水线切换 + 仅保存/保存并运行
- Sidebar 徽标真实统计;删除未使用组件与 mock 数据文件
This commit is contained in:
Logan.Li committed 2026-10-27 03:15:20 +08:00
1 parent 04d1342b27
commit 26341c3e8a
37 files changed
+5702 -4683

No files matched your search

+163 -26
View File
@@ -15,18 +15,27 @@ type User struct {
// Pipeline 流水线定义
type Pipeline struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"index" json:"name"`
Description string `json:"description"`
Type string `gorm:"default:native" json:"type"` // native | jenkins | tekton
SourceRepo string `json:"sourceRepo"`
SourceBranch string `gorm:"default:main" json:"sourceBranch"`
GitopsRepo string `json:"gitopsRepo"`
GitopsPath string `json:"gitopsPath"`
DeployType string `gorm:"default:host" json:"deployType"` // host | k8s | gitops
Env string `gorm:"default:staging" json:"env"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"index" json:"name"`
Description string `json:"description"`
Type string `gorm:"default:native" json:"type"` // native | jenkins | tekton
SourceRepo string `json:"sourceRepo"`
SourceBranch string `gorm:"default:main" json:"sourceBranch"`
GitopsRepo string `json:"gitopsRepo"`
GitopsPath string `json:"gitopsPath"`
DeployType string `gorm:"default:host" json:"deployType"` // host | k8s | gitops
Env string `gorm:"default:staging" json:"env"`
TriggerMode string `gorm:"default:manual" json:"triggerMode"` // manual | git_push | cron | webhook
CronExpr string `json:"cronExpr"`
WebhookToken string `json:"webhookToken"`
WatchBranches string `json:"watchBranches"`
Variables string `gorm:"type:text" json:"variables"` // JSON [{key,value,remark}]
CachePaths string `gorm:"type:text" json:"cachePaths"` // JSON [{path,key}]
NotifyWebhook string `json:"notifyWebhookURL"`
JenkinsJobName string `json:"jenkinsJobName"`
JenkinsServerID uint `json:"jenkinsServerId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// PipelineNode 画布节点(JSON 字段名与前端 React Flow 对齐)
@@ -67,8 +76,11 @@ type PipelineRun struct {
Type string `gorm:"default:native" json:"type"`
TriggerBy string `gorm:"default:system" json:"triggerBy"`
TriggerType string `gorm:"default:manual" json:"triggerType"` // manual|webhook|cron|batch
Status string `gorm:"default:pending" json:"status"` // pending|running|success|failed|cancelled
Status string `gorm:"default:pending" json:"status"` // pending|queued|running|success|failed|cancelled
DurationMs int64 `json:"durationMs"`
BuildNumber int `json:"buildNumber"`
ExternalRunID string `json:"externalRunId"`
ExternalURL string `json:"externalUrl"`
NodesSnapshot string `json:"nodesSnapshot"`
EdgesSnapshot string `json:"edgesSnapshot"`
StartedAt time.Time `json:"startedAt"`
@@ -103,19 +115,22 @@ type LogEntry struct {
// Application GitOps 应用
type Application struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
Repo string `json:"repo"`
Branch string `gorm:"default:main" json:"branch"`
Path string `json:"path"`
Cluster string `gorm:"default:default" json:"cluster"`
Namespace string `gorm:"default:default" json:"namespace"`
ManifestType string `gorm:"default:plain" json:"manifestType"` // helm|kustomize|plain
SyncPolicy string `gorm:"default:manual" json:"syncPolicy"` // manual|automated
AutoPrune bool `json:"autoPrune"`
SelfHeal bool `json:"selfHeal"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
Repo string `json:"repo"`
Branch string `gorm:"default:main" json:"branch"`
Path string `json:"path"`
Cluster string `gorm:"default:default" json:"cluster"`
Namespace string `gorm:"default:default" json:"namespace"`
ManifestType string `gorm:"default:plain" json:"manifestType"` // helm|kustomize|plain
SyncPolicy string `gorm:"default:manual" json:"syncPolicy"` // manual|automated
AutoPrune bool `json:"autoPrune"`
SelfHeal bool `json:"selfHeal"`
SyncStatus string `gorm:"default:Synced" json:"syncStatus"` // Synced|OutOfSync|Syncing
HealthStatus string `gorm:"default:Healthy" json:"healthStatus"` // Healthy|Progressing|Degraded
LastSyncAt *time.Time `json:"lastSyncAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Plugin 插件
@@ -133,3 +148,125 @@ type Plugin struct {
Config map[string]interface{} `gorm:"serializer:json" json:"config"`
CreatedAt time.Time `json:"createdAt"`
}
// Host 主机资源
type Host struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
IP string `json:"ip"`
SSHPort int `gorm:"default:22" json:"port"`
Username string `gorm:"default:root" json:"username"`
Tags string `gorm:"type:text" json:"tags"` // JSON ["production","web"]
Status string `gorm:"default:offline" json:"status"` // online|offline
OS string `json:"os"`
Remark string `json:"remark"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// K8sCluster 集群资源
type K8sCluster struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
Context string `json:"context"`
APIServer string `json:"apiServer"`
Version string `json:"version"`
Kubeconfig string `gorm:"type:text" json:"-"` // enc:v1: 加密,不回显
KubeconfigSet bool `gorm:"-" json:"kubeconfigSet"`
NodeCount int `json:"nodes"`
Namespaces string `gorm:"type:text" json:"namespaces"` // JSON []
Status string `gorm:"default:disconnected" json:"status"` // connected|disconnected
LastHeartbeat *time.Time `json:"lastHeartbeat"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Credential 凭证(内容 AES-GCM 加密,只写不读)
type Credential struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
Type string `gorm:"index" json:"type"` // ssh|password|docker|git|kubeconfig|aksk
Scope string `gorm:"default:全局" json:"scope"`
Content string `gorm:"type:text" json:"-"` // enc:v1: 加密 JSON
ContentSet bool `gorm:"-" json:"contentSet"`
Summary string `json:"summary"` // 脱敏摘要
UsageCount int `gorm:"default:0" json:"usageCount"`
LastUsedAt *time.Time `json:"lastUsedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// BuildNode 构建节点
type BuildNode struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
IP string `json:"ip"`
Labels string `gorm:"type:text" json:"labels"` // JSON ["docker","go"]
MaxConcurrency int `gorm:"default:2" json:"maxConcurrency"`
WorkspacePath string `gorm:"default:/data/flowstack-workspace" json:"workspacePath"`
Enabled bool `gorm:"default:true" json:"enabled"`
Status string `gorm:"default:offline" json:"status"` // online|offline|busy
CurrentJobs int `gorm:"default:0" json:"currentJobs"`
LastHeartbeat *time.Time `json:"lastHeartbeat"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// DeployTool 构建工具(检测命令真实执行;安装为保守策略:仅检测不下载)
type DeployTool struct {
ID uint `gorm:"primaryKey" json:"id"`
ToolKey string `gorm:"uniqueIndex" json:"key"`
DisplayName string `json:"name"`
Category string `gorm:"default:build" json:"category"` // build|deploy
Status string `gorm:"default:not-installed" json:"status"` // not-installed|installed|installing|failed
Version string `json:"version"` // 默认/期望版本
InstalledVersion string `json:"installedVersion"` // 真实探测到的版本
InstallMode string `gorm:"default:lazy" json:"installMode"` // preinstalled|lazy|disabled
Path string `json:"path"`
CheckCommand string `gorm:"type:text" json:"checkCommand"` // 真实版本探测命令
Enabled bool `gorm:"default:true" json:"enabled"`
LastCheck *time.Time `json:"lastCheck"`
ErrorMsg string `json:"errorMsg"`
SortOrder int `json:"sortOrder"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// WebhookEndpoint 出站 Webhook(HMAC-SHA256 签名)
type WebhookEndpoint struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Secret string `gorm:"type:text" json:"-"` // enc:v1: 加密
SecretSet bool `gorm:"-" json:"secretSet"`
Events string `gorm:"type:text" json:"events"` // JSON ["pipeline.success",...]
Active bool `gorm:"default:true" json:"active"`
LastTriggeredAt *time.Time `json:"lastTriggered"`
LastStatus string `gorm:"default:none" json:"lastStatus"` // success|failed|none
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// JenkinsServer Jenkins 实例
type JenkinsServer struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex" json:"name"`
BaseURL string `json:"baseUrl"`
Username string `json:"username"`
Token string `gorm:"type:text" json:"-"` // enc:v1: 加密
TokenSet bool `gorm:"-" json:"tokenSet"`
Enabled bool `gorm:"default:true" json:"enabled"`
Remark string `json:"remark"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// SystemSetting 系统设置(单行,ID 恒为 1)
type SystemSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Theme string `gorm:"type:text" json:"theme"` // JSON {mode,primaryColor,...}
Notification string `gorm:"type:text" json:"notification"` // JSON {email,browser,...}
ToolMode string `gorm:"default:local" json:"toolMode"` // local|jenkins
Extra string `gorm:"type:text" json:"extra"`
UpdatedAt time.Time `json:"updatedAt"`
}