Files
aiops/backend/internal/models/cicd.go
T
attacker 5333f6f04a feat(alert-center): 添加飞书Webhook通知渠道 + 告警引擎实时通知
- 后端: NotifyChannel 模型新增 feishu 类型, FeishuWebhookConfig
- 后端: TestNotifyChannel 真实发送飞书测试消息(文本格式)
- 后端: 告警引擎触发/恢复时自动发送飞书通知(sendFeishuAlert/sendFeishuRecovery)
- 后端: AlertEngine 新增 tcp_time_wait/tcp_close_wait/service_process 指标检测
- 后端: NetworkStatModel 新增 TCPCloseWait 字段
- 后端: QuickSetupRules 一键创建6条告警规则(CPU/内存/磁盘/TIME_WAIT/CLOSE_WAIT/进程)
- 后端: 注册 /alerts/quick-setup 路由
- 前端: AlertChannelDialog 新增飞书类型选项
- 前端: helpers 新增 getChannelIcon/getChannelTypeLabel 支持 feishu/dingtalk/wechat
2026-06-24 08:34:43 +00:00

250 lines
11 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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"`
JobName string `gorm:"size:128;uniqueIndex;comment:Job名称(webhook URL标识, 如 cex-admin-server)" json:"job_name,omitempty"`
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"`
// 部署模式
DeployMode string `gorm:"size:16;default:branch;comment:部署模式 branch/tag" json:"deploy_mode"`
DeployTarget string `gorm:"size:16;default:ssh;comment:部署目标 ssh/k8s" json:"deploy_target"`
// 并发控制
MaxExecutors int `gorm:"default:2;comment:最大并发执行数(1=串行,默认2)" json:"max_executors"`
// SSH 部署目标服务器 (JSON: [1,2,3])
ServerIDs string `gorm:"type:text;comment:SSH服务器ID列表(JSON)" json:"server_ids,omitempty"`
// K8s 部署目标
K8sClusterID *uint `json:"k8s_cluster_id,omitempty"` // FK → kubernetes_clusters
K8sNamespace string `gorm:"size:128;comment:K8s部署命名空间" json:"k8s_namespace,omitempty"`
// 仓库和镜像仓库关联(旧字段,待废弃)
RepoID *uint `json:"repo_id"` // FK → deploy_pipeline_repos
RegistryID *uint `json:"registry_id"` // FK → deploy_pipeline_registries
// 凭证关联(直接关联凭证 ID)
GitCredentialID *uint `json:"git_credential_id"` // FK → iam_credentials (Git Token)
RegistryCredentialID *uint `json:"registry_credential_id"` // FK → iam_credentials (Docker Password)
// 环境分组
EnvironmentID *uint `json:"environment_id"` // FK → deploy_environments
// 触发配置
TriggerMode string `gorm:"type:varchar(32);default:'manual';comment:触发方式: git_push/cron/webhook/manual" json:"trigger_mode"`
WatchBranches string `gorm:"type:varchar(256);comment:监听分支(逗号分隔, 支持通配)" json:"watch_branches,omitempty"`
ExcludeBranch string `gorm:"type:varchar(256);comment:排除分支" json:"exclude_branch,omitempty"`
CronExpr string `gorm:"type:varchar(64);comment:Cron 表达式" json:"cron_expr,omitempty"`
WebhookToken string `gorm:"type:varchar(128);comment:Webhook 签名 Token" json:"webhook_token,omitempty"`
// 缓存配置
CachePaths string `gorm:"type:text;comment:缓存路径(逗号分隔)" json:"cache_paths,omitempty"`
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"`
// 关联
Repo *PipelineRepo `json:"repo,omitempty" gorm:"foreignKey:RepoID"`
Registry *PipelineRegistry `json:"registry,omitempty" gorm:"foreignKey:RegistryID"`
Environment *DeployEnvironment `json:"environment,omitempty" gorm:"foreignKey:EnvironmentID"`
}
// 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"` // 构建产物地址
WorkspacePath string `gorm:"size:500" json:"workspace_path"` // 工作区路径
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"`
JobName string `json:"job_name"` // Webhook Job名称
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"`
// 部署模式
DeployMode string `json:"deploy_mode"` // branch / tag
DeployTarget string `json:"deploy_target"` // ssh / k8s
ServerIDs string `json:"server_ids"` // SSH 服务器ID JSON [1,2,3]
K8sClusterID *uint `json:"k8s_cluster_id"`
K8sNamespace string `json:"k8s_namespace"`
RepoID *uint `json:"repo_id"`
RegistryID *uint `json:"registry_id"`
// 凭证关联
GitCredentialID *uint `json:"git_credential_id"`
RegistryCredentialID *uint `json:"registry_credential_id"`
EnvironmentID *uint `json:"environment_id"`
// 触发配置
TriggerMode string `json:"trigger_mode"`
WatchBranches string `json:"watch_branches"`
ExcludeBranch string `json:"exclude_branch"`
CronExpr string `json:"cron_expr"`
WebhookToken string `json:"webhook_token"`
// 缓存路径
CachePaths string `json:"cache_paths"`
// 并发控制
MaxExecutors int `json:"max_executors"`
}
// UpdatePipelineRequest 更新流水线请求
type UpdatePipelineRequest struct {
Name string `json:"name"`
JobName string `json:"job_name"`
Description string `json:"description"`
Type string `json:"type"`
Source string `json:"source"`
Branch string `json:"branch"`
Dockerfile string `json:"dockerfile"`
Stages string `json:"stages"`
Variables string `json:"variables"`
DeployMode string `json:"deploy_mode"`
DeployTarget string `json:"deploy_target"`
ServerIDs string `json:"server_ids"`
K8sClusterID *uint `json:"k8s_cluster_id"`
K8sNamespace string `json:"k8s_namespace"`
RepoID *uint `json:"repo_id"`
RegistryID *uint `json:"registry_id"`
// 凭证关联
GitCredentialID *uint `json:"git_credential_id"`
RegistryCredentialID *uint `json:"registry_credential_id"`
EnvironmentID *uint `json:"environment_id"`
// 触发配置
TriggerMode string `json:"trigger_mode"`
WatchBranches string `json:"watch_branches"`
ExcludeBranch string `json:"exclude_branch"`
CronExpr string `json:"cron_expr"`
WebhookToken string `json:"webhook_token"`
// 缓存
CachePaths string `json:"cache_paths"`
Enabled *bool `json:"enabled"`
// 并发控制
MaxExecutors int `json:"max_executors"`
}
// TriggerPipelineRequest 触发流水线请求
type TriggerPipelineRequest struct {
Branch string `json:"branch"`
Tag string `json:"tag"` // 发布 Tag
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"`
}