- Rename container_clusters → kubernetes_clusters, container_topology_layouts → kubernetes_topology_layouts - LLM: add session_id to chat history for multi-turn conversation support - CI/CD: add pipeline_id, deploy_type, artifact_url, k8s_cluster_id to AppRelease - Cleanup: remove deprecated playbook handler, simplify automation models - Database: optimize auto-migrate model list - Frontend: AIOps assistant improvements, api.ts updates
142 lines
6.3 KiB
Go
142 lines
6.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
)
|
|
|
|
// Pipeline CI/CD流水线模型
|
|
type Pipeline struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:128;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:500" json:"description"`
|
|
Type string `gorm:"size:32;default:deploy" json:"type"` // build, deploy, test
|
|
Source string `gorm:"size:255" json:"source"` // Git仓库地址
|
|
Branch string `gorm:"size:64;default:main" json:"branch"`
|
|
Dockerfile string `gorm:"size:255" json:"dockerfile"`
|
|
Stages string `gorm:"type:text" json:"stages"` // JSON
|
|
Variables string `gorm:"type:text" json:"variables"` // JSON
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
LastRunAt *time.Time `json:"last_run_at"`
|
|
LastStatus string `gorm:"size:32" json:"last_status"`
|
|
RunCount int `gorm:"default:0" json:"run_count"`
|
|
SuccessCount int `gorm:"default:0" json:"success_count"`
|
|
FailCount int `gorm:"default:0" json:"fail_count"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Pipeline) TableName() string {
|
|
return "ops_pipelines"
|
|
}
|
|
|
|
// PipelineRun 流水线运行记录(CI 执行)
|
|
type PipelineRun struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
PipelineID uint `gorm:"not null" json:"pipeline_id"`
|
|
BuildNumber int `json:"build_number"`
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
|
Branch string `gorm:"size:64" json:"branch"`
|
|
CommitID string `gorm:"size:64" json:"commit_id"`
|
|
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
|
Author string `gorm:"size:64" json:"author"`
|
|
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
|
ArtifactURL string `gorm:"size:500" json:"artifact_url"` // 构建产物地址
|
|
Duration int `json:"duration"` // 秒
|
|
Stages string `gorm:"type:text" json:"stages"` // JSON
|
|
Logs string `gorm:"type:longtext" json:"logs"`
|
|
TriggeredBy string `gorm:"size:64" json:"triggered_by"`
|
|
StartedAt *time.Time `json:"started_at"`
|
|
FinishedAt *time.Time `json:"finished_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
Pipeline *Pipeline `json:"pipeline,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (PipelineRun) TableName() string {
|
|
return "ops_pipeline_runs"
|
|
}
|
|
|
|
// AppRelease 应用发布模型(CD:从 CI 产物部署到目标环境)
|
|
type AppRelease struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
PipelineID *uint `json:"pipeline_id"` // 来源流水线
|
|
PipelineRunID *uint `json:"pipeline_run_id"` // 来源 CI 执行记录
|
|
AppName string `gorm:"size:128;not null" json:"app_name"`
|
|
Version string `gorm:"size:64;not null" json:"version"`
|
|
Environment string `gorm:"size:32;not null" json:"environment"` // dev, test, staging, prod
|
|
DeployType string `gorm:"size:32;default:server" json:"deploy_type"` // server, kubernetes
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected, deploying, success, failed, rolled_back
|
|
CommitID string `gorm:"size:64" json:"commit_id"`
|
|
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
|
Author string `gorm:"size:64" json:"author"`
|
|
Approver string `gorm:"size:64" json:"approver"`
|
|
ApprovedAt *time.Time `json:"approved_at"`
|
|
DeployedAt *time.Time `json:"deployed_at"`
|
|
RollbackAt *time.Time `json:"rollback_at"`
|
|
Duration int `json:"duration"`
|
|
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
|
K8sClusterID *uint `json:"k8s_cluster_id"` // Kubernetes 部署目标集群
|
|
K8sNamespace string `gorm:"size:128" json:"k8s_namespace"` // Kubernetes 部署目标命名空间
|
|
Servers string `gorm:"type:text" json:"servers"` // JSON(传统服务器部署目标)
|
|
Description string `gorm:"size:500" json:"description"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (AppRelease) TableName() string {
|
|
return "deploy_app_releases"
|
|
}
|
|
|
|
// CreatePipelineRequest 创建流水线请求
|
|
type CreatePipelineRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Code string `json:"code" binding:"required"`
|
|
Description string `json:"description"`
|
|
Type string `json:"type" binding:"omitempty,oneof=build deploy test"`
|
|
Source string `json:"source"`
|
|
Branch string `json:"branch"`
|
|
Dockerfile string `json:"dockerfile"`
|
|
Stages string `json:"stages"`
|
|
Variables string `json:"variables"`
|
|
}
|
|
|
|
// TriggerPipelineRequest 触发流水线请求
|
|
type TriggerPipelineRequest struct {
|
|
Branch string `json:"branch"`
|
|
Variables map[string]string `json:"variables"`
|
|
}
|
|
|
|
// CreateAppReleaseRequest 创建应用发布请求
|
|
type CreateAppReleaseRequest struct {
|
|
PipelineID *uint `json:"pipeline_id"`
|
|
PipelineRunID *uint `json:"pipeline_run_id"`
|
|
AppName string `json:"app_name" binding:"required"`
|
|
Version string `json:"version" binding:"required"`
|
|
Environment string `json:"environment" binding:"required,oneof=dev test staging prod"`
|
|
DeployType string `json:"deploy_type" binding:"omitempty,oneof=server kubernetes"`
|
|
CommitID string `json:"commit_id"`
|
|
CommitMsg string `json:"commit_msg"`
|
|
ImageTag string `json:"image_tag"`
|
|
K8sClusterID *uint `json:"k8s_cluster_id"`
|
|
K8sNamespace string `json:"k8s_namespace"`
|
|
Servers []uint `json:"servers"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
// PipelineStats 流水线统计
|
|
type PipelineStats struct {
|
|
Total int64 `json:"total"`
|
|
Success int64 `json:"success"`
|
|
Failed int64 `json:"failed"`
|
|
Running int64 `json:"running"`
|
|
TodayCount int64 `json:"today_count"`
|
|
SuccessRate float64 `json:"success_rate"`
|
|
}
|