-
Notifications
You must be signed in to change notification settings - Fork 30
feat(api)!: add support for pipelines #615
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
Changes from 23 commits
9186ca1
e9e05bd
0a28d42
1ab6afe
57e5162
5366bb3
e07e7bc
66d626f
b6b840c
858c818
6f314e4
7b688cb
9a14f8c
c2fed8f
b4589f8
35b52b6
4a8f272
1195c76
740e5e0
0ec78e3
c763621
3958114
4b5bc54
d6fe4f7
29888a6
ceddb11
b90e443
cb1ac35
331b2a2
dc6c732
9ee0017
a6997a8
133439e
45f7fd1
9c1825e
8a66a15
f858ecd
be6c877
c4ec5fb
b3423d4
edbc030
f8eb267
bfbc27f
782c15f
0ef35b5
a794666
159df8e
760ed7c
d973677
33d0d03
1183bd4
2e147f7
256369e
c17860d
7050468
da3142e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright (c) 2022 Target Brands, Inc. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by the LICENSE file in this repository. | ||
|
|
||
| // nolint: dupl // ignore similar code with expand | ||
| package pipeline | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/go-vela/server/compiler" | ||
| "github.com/go-vela/server/router/middleware/org" | ||
| "github.com/go-vela/server/router/middleware/pipeline" | ||
| "github.com/go-vela/server/router/middleware/repo" | ||
| "github.com/go-vela/server/router/middleware/user" | ||
| "github.com/go-vela/server/util" | ||
| "github.com/go-vela/types" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| // swagger:operation POST /api/v1/pipelines/{org}/{repo}/{pipeline}/compile pipelines CompilePipeline | ||
| // | ||
| // Get, expand and compile a pipeline configuration from the database | ||
| // | ||
| // --- | ||
| // produces: | ||
| // - application/x-yaml | ||
| // - application/json | ||
| // parameters: | ||
| // - in: path | ||
| // name: repo | ||
| // description: Name of the repo | ||
| // required: true | ||
| // type: string | ||
| // - in: path | ||
| // name: org | ||
| // description: Name of the org | ||
| // required: true | ||
| // type: string | ||
| // - in: query | ||
| // name: ref | ||
| // description: Ref for retrieving pipeline configuration file | ||
| // type: string | ||
| // - in: query | ||
| // name: output | ||
| // description: Output string for specifying output format | ||
| // type: string | ||
jbrockopp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // security: | ||
| // - ApiKeyAuth: [] | ||
| // responses: | ||
| // '200': | ||
| // description: Successfully retrieved and compiled the pipeline | ||
| // schema: | ||
| // "$ref": "#/definitions/PipelineBuild" | ||
| // '400': | ||
| // description: Unable to validate the pipeline configuration | ||
| // schema: | ||
| // "$ref": "#/definitions/Error" | ||
| // '404': | ||
| // description: Unable to retrieve the pipeline configuration | ||
| // schema: | ||
| // "$ref": "#/definitions/Error" | ||
|
|
||
| // CompilePipeline represents the API handler to capture, | ||
| // expand and compile a pipeline configuration. | ||
| func CompilePipeline(c *gin.Context) { | ||
| // capture middleware values | ||
| m := c.MustGet("metadata").(*types.Metadata) | ||
| o := org.Retrieve(c) | ||
| p := pipeline.Retrieve(c) | ||
| r := repo.Retrieve(c) | ||
| u := user.Retrieve(c) | ||
|
|
||
| entry := fmt.Sprintf("%s/%d", r.GetFullName(), p.GetNumber()) | ||
|
|
||
| // update engine logger with API metadata | ||
| // | ||
| // https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields | ||
| logrus.WithFields(logrus.Fields{ | ||
| "org": o, | ||
| "pipeline": p.GetNumber(), | ||
| "repo": r.GetName(), | ||
| "user": u.GetName(), | ||
| }).Infof("compiling pipeline %s", entry) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the given fields, the contents of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We certainly could 👍 I'm leaning towards leaving it in there since it doesn't hurt. This pattern is adopted from existing log entires we already established for other API endpoints. So if we did want to switch this up, I think we'd have to go back and apply the same changes for consistency.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point, I'd vote for removing it maybe in another PR. Seems like a waste of bytes that can add up - then again, this is more compact than logging as separate JSON fields :disappear:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I see where you're coming from on that 👍 To me, the message for the log entry is designed for human processing i.e. user who manually reviews the log entries or using a tool such as In those scenarios, it can add a bit of complexity when trying to search for multiple fields but not impossible: # searching for specific message
cat log.txt | grep '<org>/<repo>/<commit>'
# searching for specific fields
cat log.txt | grep '"org": <org>' | grep '"repo": <repo>' | grep '"pipeline": <commit>'While the fields for the log entry are designed for system processing i.e. most apps/tools consuming logs enable filtering on one or more fields which improves this experience However, if folks feel strongly enough about it, then I could get behind shortening the message |
||
|
|
||
| // ensure we use the expected pipeline type when compiling | ||
| r.SetPipelineType(p.GetType()) | ||
|
|
||
| // create the compiler object | ||
| compiler := compiler.FromContext(c).Duplicate().WithMetadata(m).WithRepo(r).WithUser(u) | ||
|
|
||
| // compile the pipeline | ||
| pipeline, _, err := compiler.CompileLite(p.GetData(), true, true, nil) | ||
| if err != nil { | ||
| retErr := fmt.Errorf("unable to compile pipeline %s: %w", entry, err) | ||
|
|
||
| util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| writeOutput(c, pipeline) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.