Skip to content

Commit

Permalink
feat: support tekton via cloud event (#67)
Browse files Browse the repository at this point in the history
Why:
- support trigger tekton as backend pipeline

How:
- add a field: pipelineEngine to select backend pipeline, when it is set
to tekton, it will trigger tekton
- accept cloud event message, it will record triggered pipelines, and
calculate status according to these pipeline status

Todo:
- accept tekton message still need testing
- only support branch right now, devbuild usually use PR

---------

Signed-off-by: lijie <lijie@pingcap.com>
  • Loading branch information
lijie authored Feb 22, 2024
1 parent 0f5542f commit 0f07b00
Show file tree
Hide file tree
Showing 28 changed files with 2,052 additions and 90 deletions.
2 changes: 2 additions & 0 deletions tibuild/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ test:
build.server: swagger test
go build -o ${GO_BINARY} ${TIBUILD_MAIN_FILE}

server:
go run ${TIBUILD_MAIN_FILE}

# =============================================================================
# The following are common deployment commands
Expand Down
10 changes: 9 additions & 1 deletion tibuild/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"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"
events "github.com/PingCAP-QE/ee-apps/tibuild/pkg/webhook/handler"

_ "github.com/PingCAP-QE/ee-apps/tibuild/docs"
)
Expand Down Expand Up @@ -102,7 +103,8 @@ func routeRestAPI(router *gin.Engine, cfg *configs.ConfigYaml) {
panic(err)
}
devBuildGroup := apiGroup.Group("/devbuilds")
devBuildHandler := controllers.NewDevBuildHandler(context.Background(), jenkins, database.DBConn.DB, cfg.RestApiSecret)
devBuildServer := controllers.NewDevBuildServer(jenkins, database.DBConn.DB, cfg.CloudEvent.Endpoint)
devBuildHandler := controllers.NewDevBuildHandler(devBuildServer, cfg.RestApiSecret)
{
devBuildGroup.POST("", devBuildHandler.Create)
devBuildGroup.GET("", devBuildHandler.List)
Expand All @@ -116,4 +118,10 @@ func routeRestAPI(router *gin.Engine, cfg *configs.ConfigYaml) {
{
artifactGroup.POST("/sync-image", artifactHelper.SyncImage)
}

event := events.NewHandler(devBuildServer)
eventsGroup := apiGroup.Group("/event")
{
eventsGroup.POST("", event.Receive)
}
}
3 changes: 3 additions & 0 deletions tibuild/commons/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type ConfigYaml struct {
}

RestApiSecret RestApiSecret
CloudEvent struct {
Endpoint string
}
}

type RestApiSecret struct {
Expand Down
115 changes: 115 additions & 0 deletions tibuild/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ const docTemplate = `{
"component": {
"type": "string"
},
"oras": {
"$ref": "#/definitions/service.OrasFile"
},
"platform": {
"type": "string"
},
Expand Down Expand Up @@ -461,6 +464,9 @@ const docTemplate = `{
"features": {
"type": "string"
},
"gitHash": {
"type": "string"
},
"gitRef": {
"type": "string"
},
Expand All @@ -473,6 +479,9 @@ const docTemplate = `{
"isPushGCR": {
"type": "boolean"
},
"pipelineEngine": {
"$ref": "#/definitions/service.PipelineEngine"
},
"pluginGitRef": {
"type": "string"
},
Expand Down Expand Up @@ -516,6 +525,9 @@ const docTemplate = `{
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
},
"tektonStatus": {
"$ref": "#/definitions/service.TektonStatus"
}
}
},
Expand All @@ -541,6 +553,48 @@ const docTemplate = `{
}
}
},
"service.OrasArtifact": {
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {
"type": "string"
}
},
"repo": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"service.OrasFile": {
"type": "object",
"properties": {
"file": {
"type": "string"
},
"repo": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"service.PipelineEngine": {
"type": "string",
"enum": [
"jenkins",
"tekton"
],
"x-enum-varnames": [
"JenkinsEngine",
"TektonEngine"
]
},
"service.Product": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -614,6 +668,67 @@ const docTemplate = `{
"type": "string"
}
}
},
"service.TektonPipeline": {
"type": "object",
"properties": {
"gitHash": {
"type": "string"
},
"images": {
"type": "array",
"items": {
"$ref": "#/definitions/service.ImageArtifact"
}
},
"name": {
"type": "string"
},
"orasArtifacts": {
"type": "array",
"items": {
"$ref": "#/definitions/service.OrasArtifact"
}
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"type": "string"
},
"platform": {
"type": "string"
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
},
"url": {
"type": "string"
}
}
},
"service.TektonStatus": {
"type": "object",
"properties": {
"buildReport": {
"$ref": "#/definitions/service.BuildReport"
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"type": "string"
},
"pipelines": {
"type": "array",
"items": {
"$ref": "#/definitions/service.TektonPipeline"
}
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
}
}
}
}
}`
Expand Down
115 changes: 115 additions & 0 deletions tibuild/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
"component": {
"type": "string"
},
"oras": {
"$ref": "#/definitions/service.OrasFile"
},
"platform": {
"type": "string"
},
Expand Down Expand Up @@ -449,6 +452,9 @@
"features": {
"type": "string"
},
"gitHash": {
"type": "string"
},
"gitRef": {
"type": "string"
},
Expand All @@ -461,6 +467,9 @@
"isPushGCR": {
"type": "boolean"
},
"pipelineEngine": {
"$ref": "#/definitions/service.PipelineEngine"
},
"pluginGitRef": {
"type": "string"
},
Expand Down Expand Up @@ -504,6 +513,9 @@
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
},
"tektonStatus": {
"$ref": "#/definitions/service.TektonStatus"
}
}
},
Expand All @@ -529,6 +541,48 @@
}
}
},
"service.OrasArtifact": {
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {
"type": "string"
}
},
"repo": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"service.OrasFile": {
"type": "object",
"properties": {
"file": {
"type": "string"
},
"repo": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"service.PipelineEngine": {
"type": "string",
"enum": [
"jenkins",
"tekton"
],
"x-enum-varnames": [
"JenkinsEngine",
"TektonEngine"
]
},
"service.Product": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -602,6 +656,67 @@
"type": "string"
}
}
},
"service.TektonPipeline": {
"type": "object",
"properties": {
"gitHash": {
"type": "string"
},
"images": {
"type": "array",
"items": {
"$ref": "#/definitions/service.ImageArtifact"
}
},
"name": {
"type": "string"
},
"orasArtifacts": {
"type": "array",
"items": {
"$ref": "#/definitions/service.OrasArtifact"
}
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"type": "string"
},
"platform": {
"type": "string"
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
},
"url": {
"type": "string"
}
}
},
"service.TektonStatus": {
"type": "object",
"properties": {
"buildReport": {
"$ref": "#/definitions/service.BuildReport"
},
"pipelineEndAt": {
"type": "string"
},
"pipelineStartAt": {
"type": "string"
},
"pipelines": {
"type": "array",
"items": {
"$ref": "#/definitions/service.TektonPipeline"
}
},
"status": {
"$ref": "#/definitions/service.BuildStatus"
}
}
}
}
}
Loading

0 comments on commit 0f07b00

Please sign in to comment.