- 前端: React 18 + TypeScript + Vite + Tailwind CSS + shadcn/ui - 后端: Go + Gin + GORM + JWT (golang-jwt/jwt/v5) - 功能: 服务器管理、K8s集群、监控告警、CI/CD、自动化运维、审批流程、审计日志 - 文档: 设计文档(ROADMAP/PDD/架构/模块)
131 lines
5.3 KiB
Go
131 lines
5.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 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"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Pipeline) TableName() string {
|
|
return "pipelines"
|
|
}
|
|
|
|
// PipelineRun 流水线运行记录
|
|
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"`
|
|
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 "pipeline_runs"
|
|
}
|
|
|
|
// AppRelease 应用发布模型
|
|
type AppRelease struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
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
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, building, 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"`
|
|
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"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (AppRelease) TableName() string {
|
|
return "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 {
|
|
AppName string `json:"app_name" binding:"required"`
|
|
Version string `json:"version" binding:"required"`
|
|
Environment string `json:"environment" binding:"required,oneof=dev test staging prod"`
|
|
CommitID string `json:"commit_id"`
|
|
CommitMsg string `json:"commit_msg"`
|
|
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"`
|
|
}
|