Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tibuild): rename internalpkg to internal #38

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tibuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tibuild
└── configs/ # Global configuration reader
└── database/ # Database connectors
└── httpclient/ # Http client utils
└── internalpkg/ # Business code & function
└── internal/ # Business code & function
└── entity/ # Object entity
└── service/ # Service for controller/
└── controller/ # Deal with http request
Expand Down
2 changes: 1 addition & 1 deletion tibuild/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/PingCAP-QE/ee-apps/tibuild/commons/configs"
"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/controller"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/controller"
controllers "github.com/PingCAP-QE/ee-apps/tibuild/pkg/rest/controller"
"github.com/PingCAP-QE/ee-apps/tibuild/pkg/rest/service"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin/binding"

"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/entity"
)

type PipelinesListShowRequest struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/PingCAP-QE/ee-apps/tibuild/commons/configs"
"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/gojenkins"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/service"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/service"
)

type PipelineTriggerStruct struct {
Expand Down Expand Up @@ -58,9 +58,12 @@ type WhiteList struct {
}

func PipelineTrigger(c *gin.Context) {
log.Println(c.Request.URL.Path)

var params PipelineTriggerStruct
println("start.....")
err := c.ShouldBind(&params)
if err := c.Bind(&params); err != nil {
return
}
println(params.PipelineId)
println(params.TriggeredBy)
println(params.ArtifactType)
Expand All @@ -69,17 +72,6 @@ func PipelineTrigger(c *gin.Context) {
println(params.Branch)
println(params.Version)

if err != nil {
c.Error(err)
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": err.Error(),
"data": params,
})
return
}
println("finished......")

// 查数据库关联
var tibuildInfo []TibuildInfo
database.DBConn.DB.Where(&TibuildInfo{PipelineId: params.PipelineId}).Find(&tibuildInfo)
Expand Down Expand Up @@ -107,7 +99,6 @@ func PipelineTrigger(c *gin.Context) {
// jenkins
ctx := context.Background()
jenkins, _ := gojenkins.CreateJenkins(nil, "https://cd.pingcap.net/", configs.Config.Jenkins.UserName, configs.Config.Jenkins.PassWord).Init(ctx)
copyContext := c.Copy()
var cstSh, _ = time.LoadLocation("Asia/Shanghai") //上海

ps := entity.PipelinesListShow{
Expand All @@ -134,89 +125,89 @@ func PipelineTrigger(c *gin.Context) {

params_trans := make(map[string]string)
params_trans["PIPELINE_BUILD_ID"] = strconv.Itoa(ps.PipelineBuildId)
go func() {
job_name_tmp := strings.Split(tibuildInfo[0].Pipeline, "/job/")
// 请求数据入库,数据库生成自增id并返回
switch params.PipelineId {
case 1, 2, 3, 4, 5, 6:
fmt.Println("触发构建的是多分支流水线,没有传入参数")
case 7:
fmt.Println("Tab展示名:Nightly Image Build For QA")
if params.Branch == "master" {
params_trans["GIT_BRANCH"] = "master"
params_trans["NEED_MULTIARCH"] = "true"
} else {
params_trans["GIT_BRANCH"] = params.Branch
params_trans["NEED_MULTIARCH"] = "false"
}
params_trans["FORCE_REBUILD"] = "false"

case 8:
fmt.Println("Tab展示名:Nightly Image Build to Dockerhub")

case 9:
fmt.Println("Tab展示名:Nightly TiUP Build")
case 10:
params_trans["RELEASE_BRANCH"] = params.Branch
params_trans["RELEASE_TAG"] = params.Version
case 11:
params_trans["RELEASE_TAG"] = params.Version
params_trans["RELEASE_BRANCH"] = params.Branch
params_trans["NEED_MULTIARCH"] = "true"
params_trans["DEBUG_MODE"] = "false"
case 12:
params_trans["PRODUCT"] = params.Component
if params.Component == "ticdc" || params.Component == "dm" {
params_trans["REPO"] = "tiflow"
} else if params.Component == "tidb" || params.Component == "dumpling" || params.Component == "lightning" || params.Component == "br" {
params_trans["REPO"] = "tidb"
} else {
params_trans["REPO"] = params.Component
}
params_trans["HOTFIX_TAG"] = params.Version
if params.PushGCR == "Yes" {
params_trans["PUSH_GCR"] = "true"
} else {
params_trans["PUSH_GCR"] = "false"
}
if params.ArtifactType == "enterprise image" {
params_trans["PUSH_DOCKER_HUB"] = "false"
params_trans["EDITION"] = "enterprise"
} else {
params_trans["PUSH_DOCKER_HUB"] = "true"
params_trans["EDITION"] = "community"
}
params_trans["FORCE_REBUILD"] = "true"
params_trans["DEBUG"] = "false"
if params.Arch == "All" {
params_trans["ARCH"] = "both"
} else if params.Arch == "linux-amd64" {
params_trans["ARCH"] = "amd64"
} else {
params_trans["ARCH"] = "arm64"
}

}
log.Println(params_trans)

if len(job_name_tmp) <= 1 {
println("Jenkins uri 非法!")
} else if len(job_name_tmp) == 2 {
job_name := strings.Split(job_name_tmp[1], "/")[0]
println(job_name)
service.Job_Build(jenkins, ctx, job_name, params_trans, int64(ps.PipelineBuildId))
} else {
job_name := job_name_tmp[1] + "/" + job_name_tmp[2]
println(job_name)
service.Job_Build(jenkins, ctx, job_name, params_trans, int64(ps.PipelineBuildId))
}
go triggerJenkinsJob(ctx, &tibuildInfo[0], &params, params_trans, jenkins, int64(ps.PipelineBuildId))

log.Println(copyContext.Request.URL.Path)
}()
log.Println(params_trans)
res := &TriggerRes{PipelineBuildId: ps.PipelineBuildId}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"message": "请求成功",
"data": res,
"data": &TriggerRes{PipelineBuildId: ps.PipelineBuildId},
})
}

func triggerJenkinsJob(ctx context.Context, tibuildInfo *TibuildInfo, params *PipelineTriggerStruct, params_trans map[string]string, jenkins *gojenkins.Jenkins, pipelineBuildID int64) {
switch params.PipelineId {
case 1, 2, 3, 4, 5, 6:
fmt.Println("触发构建的是多分支流水线,没有传入参数")
case 7:
fmt.Println("Tab展示名:Nightly Image Build For QA")
if params.Branch == "master" {
params_trans["GIT_BRANCH"] = "master"
params_trans["NEED_MULTIARCH"] = "true"
} else {
params_trans["GIT_BRANCH"] = params.Branch
params_trans["NEED_MULTIARCH"] = "false"
}
params_trans["FORCE_REBUILD"] = "false"

case 8:
fmt.Println("Tab展示名:Nightly Image Build to Dockerhub")

case 9:
fmt.Println("Tab展示名:Nightly TiUP Build")
case 10:
params_trans["RELEASE_BRANCH"] = params.Branch
params_trans["RELEASE_TAG"] = params.Version
case 11:
params_trans["RELEASE_TAG"] = params.Version
params_trans["RELEASE_BRANCH"] = params.Branch
params_trans["NEED_MULTIARCH"] = "true"
params_trans["DEBUG_MODE"] = "false"
case 12: // dev-build
params_trans["PRODUCT"] = params.Component
if params.Component == "ticdc" || params.Component == "dm" {
params_trans["REPO"] = "tiflow"
} else if params.Component == "tidb" || params.Component == "dumpling" || params.Component == "lightning" || params.Component == "br" {
params_trans["REPO"] = "tidb"
} else {
params_trans["REPO"] = params.Component
}
params_trans["HOTFIX_TAG"] = params.Version
if params.PushGCR == "Yes" {
params_trans["PUSH_GCR"] = "true"
} else {
params_trans["PUSH_GCR"] = "false"
}
if params.ArtifactType == "enterprise image" {
params_trans["PUSH_DOCKER_HUB"] = "false"
params_trans["EDITION"] = "enterprise"
} else {
params_trans["PUSH_DOCKER_HUB"] = "true"
params_trans["EDITION"] = "community"
}
params_trans["FORCE_REBUILD"] = "true"
params_trans["DEBUG"] = "false"
if params.Arch == "All" {
params_trans["ARCH"] = "both"
} else if params.Arch == "linux-amd64" {
params_trans["ARCH"] = "amd64"
} else {
params_trans["ARCH"] = "arm64"
}

}

job_name_tmp := strings.Split(tibuildInfo.Pipeline, "/job/")
if len(job_name_tmp) <= 1 {
println("Jenkins uri 非法!")
} else if len(job_name_tmp) == 2 {
job_name := strings.Split(job_name_tmp[1], "/")[0]
println(job_name)
service.Job_Build(jenkins, ctx, job_name, params_trans, pipelineBuildID)
} else {
job_name := job_name_tmp[1] + "/" + job_name_tmp[2]
println(job_name)
service.Job_Build(jenkins, ctx, job_name, params_trans, pipelineBuildID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin/binding"

"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/entity"
)

type RequestResultRequestStruct struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin/binding"

"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/entity"
)

type RequestRotationRequestStruct struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/PingCAP-QE/ee-apps/tibuild/commons/database"
"github.com/PingCAP-QE/ee-apps/tibuild/gojenkins"
"github.com/PingCAP-QE/ee-apps/tibuild/internalpkg/entity"
"github.com/PingCAP-QE/ee-apps/tibuild/internal/entity"
)

func Job_Build(jenkins *gojenkins.Jenkins, ctx context.Context, jobname string, params map[string]string, pipeline_build_id int64) {
Expand Down