update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
+116
-60
@@ -6,8 +6,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"ezops/model"
|
||||
"ezops/middleware"
|
||||
"ezops/model"
|
||||
ezredis "ezops/pkg/redis"
|
||||
"ezops/pkg/toolinstaller"
|
||||
|
||||
@@ -69,7 +69,7 @@ func NewPipelineHandler(db *gorm.DB, cache ezredis.Cache, ti *toolinstaller.Tool
|
||||
// PipelineListItem 列表项(含最近一次运行摘要)// Logan.Li
|
||||
type PipelineListItem struct {
|
||||
model.Pipeline
|
||||
LastRunStages string `json:"last_run_stages,omitempty"` // JSON: [{name,status}]
|
||||
LastRunStages string `json:"last_run_stages,omitempty"` // JSON: [{name,status}]
|
||||
LastImageTag string `json:"last_image_tag,omitempty"`
|
||||
LastCommitID string `json:"last_commit_id,omitempty"`
|
||||
LastRunDuration int `json:"last_duration,omitempty"`
|
||||
@@ -123,7 +123,7 @@ func (h *PipelineHandler) ListPipelines(c *gin.Context) {
|
||||
}
|
||||
// 子查询:每个 pipeline_id 的最新 run id
|
||||
var latestRuns []model.PipelineRun
|
||||
h.db.Where("id IN (SELECT MAX(id) FROM ops_pipeline_runs WHERE pipeline_id IN ? AND status IN ('success','failed','running','pending') GROUP BY pipeline_id)", pids).
|
||||
h.db.Where("id IN (SELECT MAX(id) FROM deploy_pipeline_runs WHERE pipeline_id IN ? AND status IN ('success','failed','running','pending') GROUP BY pipeline_id)", pids).
|
||||
Find(&latestRuns)
|
||||
runMap := map[uint]*model.PipelineRun{}
|
||||
for i := range latestRuns {
|
||||
@@ -147,8 +147,8 @@ func (h *PipelineHandler) ListPipelines(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Response{
|
||||
Code: 200,
|
||||
Data: model.ListResponse{List: items, Total: total},
|
||||
Code: 200,
|
||||
Data: model.ListResponse{List: items, Total: total},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -211,30 +211,28 @@ func (h *PipelineHandler) CreatePipeline(c *gin.Context) {
|
||||
}
|
||||
|
||||
pipeline := model.Pipeline{
|
||||
Name: req.Name,
|
||||
Code: req.Code,
|
||||
JobName: req.JobName,
|
||||
Description: req.Description,
|
||||
Type: req.Type,
|
||||
Source: req.Source,
|
||||
Branch: req.Branch,
|
||||
Dockerfile: req.Dockerfile,
|
||||
Stages: req.Stages,
|
||||
Variables: req.Variables,
|
||||
DeployMode: req.DeployMode,
|
||||
DeployTarget: req.DeployTarget,
|
||||
ServerIDs: req.ServerIDs,
|
||||
DeployRemotePath: req.DeployRemotePath,
|
||||
DeployScript: req.DeployScript,
|
||||
K8sClusterID: req.K8sClusterID,
|
||||
K8sNamespace: req.K8sNamespace,
|
||||
K8sDeployment: req.K8sDeployment,
|
||||
K8sContainerName: req.K8sContainerName,
|
||||
RepoID: req.RepoID,
|
||||
RegistryID: req.RegistryID,
|
||||
Name: req.Name,
|
||||
Code: req.Code,
|
||||
JobName: req.JobName,
|
||||
Description: req.Description,
|
||||
Type: req.Type,
|
||||
Source: req.Source,
|
||||
Branch: req.Branch,
|
||||
Dockerfile: req.Dockerfile,
|
||||
Stages: req.Stages,
|
||||
Variables: req.Variables,
|
||||
DeployMode: req.DeployMode,
|
||||
DeployTarget: req.DeployTarget,
|
||||
ServerIDs: req.ServerIDs,
|
||||
DeployRemotePath: req.DeployRemotePath,
|
||||
DeployScript: req.DeployScript,
|
||||
K8sClusterID: req.K8sClusterID,
|
||||
K8sNamespace: req.K8sNamespace,
|
||||
K8sDeployment: req.K8sDeployment,
|
||||
K8sContainerName: req.K8sContainerName,
|
||||
GitCredentialID: req.GitCredentialID,
|
||||
RegistryCredentialID: req.RegistryCredentialID,
|
||||
EnvironmentID: req.EnvironmentID,
|
||||
EnvironmentID: req.EnvironmentID,
|
||||
// 触发配置
|
||||
TriggerMode: req.TriggerMode,
|
||||
WatchBranches: req.WatchBranches,
|
||||
@@ -246,7 +244,7 @@ func (h *PipelineHandler) CreatePipeline(c *gin.Context) {
|
||||
// 并发控制
|
||||
MaxExecutors: req.MaxExecutors,
|
||||
BuildNodeID: req.BuildNodeID,
|
||||
Enabled: true,
|
||||
Enabled: true,
|
||||
}
|
||||
|
||||
if err := h.db.Create(&pipeline).Error; err != nil {
|
||||
@@ -301,38 +299,96 @@ func (h *PipelineHandler) UpdatePipeline(c *gin.Context) {
|
||||
}
|
||||
|
||||
updates := map[string]interface{}{}
|
||||
if req.Name != "" { updates["name"] = req.Name }
|
||||
if req.JobName != "" { updates["job_name"] = req.JobName }
|
||||
if req.Description != "" { updates["description"] = req.Description }
|
||||
if req.Type != "" { updates["type"] = req.Type }
|
||||
if req.Source != "" { updates["source"] = req.Source }
|
||||
if req.Branch != "" { updates["branch"] = req.Branch }
|
||||
if req.Dockerfile != "" { updates["dockerfile"] = req.Dockerfile }
|
||||
if req.Stages != "" { updates["stages"] = req.Stages }
|
||||
if req.Variables != "" { updates["variables"] = req.Variables }
|
||||
if req.DeployMode != "" { updates["deploy_mode"] = req.DeployMode }
|
||||
if req.DeployTarget != "" { updates["deploy_target"] = req.DeployTarget }
|
||||
if req.ServerIDs != "" { updates["server_ids"] = req.ServerIDs }
|
||||
if req.DeployRemotePath != "" { updates["deploy_remote_path"] = req.DeployRemotePath }
|
||||
if req.DeployScript != "" { updates["deploy_script"] = req.DeployScript }
|
||||
if req.K8sNamespace != "" { updates["k8s_namespace"] = req.K8sNamespace }
|
||||
if req.K8sDeployment != "" { updates["k8s_deployment"] = req.K8sDeployment }
|
||||
if req.K8sContainerName != "" { updates["k8s_container_name"] = req.K8sContainerName }
|
||||
if req.K8sClusterID != nil { updates["k8s_cluster_id"] = req.K8sClusterID }
|
||||
if req.RepoID != nil { updates["repo_id"] = req.RepoID }
|
||||
if req.RegistryID != nil { updates["registry_id"] = req.RegistryID }
|
||||
if req.GitCredentialID != nil { updates["git_credential_id"] = req.GitCredentialID }
|
||||
if req.RegistryCredentialID != nil { updates["registry_credential_id"] = req.RegistryCredentialID }
|
||||
if req.EnvironmentID != nil { updates["environment_id"] = req.EnvironmentID }
|
||||
if req.TriggerMode != "" { updates["trigger_mode"] = req.TriggerMode }
|
||||
if req.WatchBranches != "" { updates["watch_branches"] = req.WatchBranches }
|
||||
if req.ExcludeBranch != "" { updates["exclude_branch"] = req.ExcludeBranch }
|
||||
if req.CronExpr != "" { updates["cron_expr"] = req.CronExpr }
|
||||
if req.WebhookToken != "" { updates["webhook_token"] = req.WebhookToken }
|
||||
if req.CachePaths != "" { updates["cache_paths"] = req.CachePaths }
|
||||
if req.Enabled != nil { updates["enabled"] = req.Enabled }
|
||||
if req.MaxExecutors > 0 { updates["max_executors"] = req.MaxExecutors }
|
||||
if req.BuildNodeID != nil { updates["build_node_id"] = req.BuildNodeID }
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.JobName != "" {
|
||||
updates["job_name"] = req.JobName
|
||||
}
|
||||
if req.Description != "" {
|
||||
updates["description"] = req.Description
|
||||
}
|
||||
if req.Type != "" {
|
||||
updates["type"] = req.Type
|
||||
}
|
||||
if req.Source != "" {
|
||||
updates["source"] = req.Source
|
||||
}
|
||||
if req.Branch != "" {
|
||||
updates["branch"] = req.Branch
|
||||
}
|
||||
if req.Dockerfile != "" {
|
||||
updates["dockerfile"] = req.Dockerfile
|
||||
}
|
||||
if req.Stages != "" {
|
||||
updates["stages"] = req.Stages
|
||||
}
|
||||
if req.Variables != "" {
|
||||
updates["variables"] = req.Variables
|
||||
}
|
||||
if req.DeployMode != "" {
|
||||
updates["deploy_mode"] = req.DeployMode
|
||||
}
|
||||
if req.DeployTarget != "" {
|
||||
updates["deploy_target"] = req.DeployTarget
|
||||
}
|
||||
if req.ServerIDs != "" {
|
||||
updates["server_ids"] = req.ServerIDs
|
||||
}
|
||||
if req.DeployRemotePath != "" {
|
||||
updates["deploy_remote_path"] = req.DeployRemotePath
|
||||
}
|
||||
if req.DeployScript != "" {
|
||||
updates["deploy_script"] = req.DeployScript
|
||||
}
|
||||
if req.K8sNamespace != "" {
|
||||
updates["k8s_namespace"] = req.K8sNamespace
|
||||
}
|
||||
if req.K8sDeployment != "" {
|
||||
updates["k8s_deployment"] = req.K8sDeployment
|
||||
}
|
||||
if req.K8sContainerName != "" {
|
||||
updates["k8s_container_name"] = req.K8sContainerName
|
||||
}
|
||||
if req.K8sClusterID != nil {
|
||||
updates["k8s_cluster_id"] = req.K8sClusterID
|
||||
}
|
||||
if req.GitCredentialID != nil {
|
||||
updates["git_credential_id"] = req.GitCredentialID
|
||||
}
|
||||
if req.RegistryCredentialID != nil {
|
||||
updates["registry_credential_id"] = req.RegistryCredentialID
|
||||
}
|
||||
if req.EnvironmentID != nil {
|
||||
updates["environment_id"] = req.EnvironmentID
|
||||
}
|
||||
if req.TriggerMode != "" {
|
||||
updates["trigger_mode"] = req.TriggerMode
|
||||
}
|
||||
if req.WatchBranches != "" {
|
||||
updates["watch_branches"] = req.WatchBranches
|
||||
}
|
||||
if req.ExcludeBranch != "" {
|
||||
updates["exclude_branch"] = req.ExcludeBranch
|
||||
}
|
||||
if req.CronExpr != "" {
|
||||
updates["cron_expr"] = req.CronExpr
|
||||
}
|
||||
if req.WebhookToken != "" {
|
||||
updates["webhook_token"] = req.WebhookToken
|
||||
}
|
||||
if req.CachePaths != "" {
|
||||
updates["cache_paths"] = req.CachePaths
|
||||
}
|
||||
if req.Enabled != nil {
|
||||
updates["enabled"] = req.Enabled
|
||||
}
|
||||
if req.MaxExecutors > 0 {
|
||||
updates["max_executors"] = req.MaxExecutors
|
||||
}
|
||||
if req.BuildNodeID != nil {
|
||||
updates["build_node_id"] = req.BuildNodeID
|
||||
}
|
||||
|
||||
if err := h.db.Model(&pipeline).Updates(updates).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.Response{
|
||||
|
||||
Reference in new issue
Block a user