-
Notifications
You must be signed in to change notification settings - Fork 29
feat: deployment config for expected params and targets #1214
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26fd51e
feat: deployment config for expected params and targets
ecrupper 04d6ac1
Merge branch 'main' into feat/deployment-config
ecrupper 9a8884c
Merge branch 'main' into feat/deployment-config
ecrupper 8776896
Merge branch 'main' into feat/deployment-config
ecrupper 2860d95
Merge branch 'main' into feat/deployment-config
ecrupper c2c20bb
Merge branch 'main' into feat/deployment-config
ecrupper b25ab8d
update API comment
ecrupper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package deployment | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"gorm.io/gorm" | ||
|
||
"github.com/go-vela/server/compiler" | ||
"github.com/go-vela/server/database" | ||
"github.com/go-vela/server/router/middleware/repo" | ||
"github.com/go-vela/server/router/middleware/user" | ||
"github.com/go-vela/server/scm" | ||
"github.com/go-vela/server/util" | ||
) | ||
|
||
// swagger:operation GET /api/v1/deployments/{org}/{repo}/config deployments GetDeploymentConfig | ||
// | ||
// Get a deployment config | ||
// | ||
// --- | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - in: path | ||
// name: org | ||
// description: Name of the organization | ||
// required: true | ||
// type: string | ||
// - in: path | ||
// name: repo | ||
// description: Name of the repository | ||
// required: true | ||
// type: string | ||
// - in: query | ||
// name: ref | ||
// description: Ref to target for the deployment config | ||
// type: string | ||
// security: | ||
// - ApiKeyAuth: [] | ||
// responses: | ||
// '200': | ||
// description: Successfully retrieved the deployment config | ||
// schema: | ||
// "$ref": "#/definitions/Deployment" | ||
// '400': | ||
// description: Invalid request payload or path | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '401': | ||
// description: Unauthorized | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '404': | ||
// description: Not found | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
// '500': | ||
// description: Unexpected server error | ||
// schema: | ||
// "$ref": "#/definitions/Error" | ||
|
||
// GetDeploymentConfig represents the API handler to get a deployment config at a given ref. | ||
func GetDeploymentConfig(c *gin.Context) { | ||
// capture middleware values | ||
l := c.MustGet("logger").(*logrus.Entry) | ||
r := repo.Retrieve(c) | ||
u := user.Retrieve(c) | ||
|
||
ctx := c.Request.Context() | ||
|
||
// capture ref from parameters - use default branch if not provided | ||
ref := util.QueryParameter(c, "ref", r.GetBranch()) | ||
|
||
entry := fmt.Sprintf("%s@%s", r.GetFullName(), ref) | ||
|
||
l.Debugf("reading deployment config %s", entry) | ||
|
||
var config []byte | ||
|
||
// check if the pipeline exists in the database | ||
p, err := database.FromContext(c).GetPipelineForRepo(ctx, ref, r) | ||
if err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
l.Debugf("pipeline %s not found in database, fetching from scm", entry) | ||
|
||
config, err = scm.FromContext(c).ConfigBackoff(ctx, u, r, ref) | ||
if err != nil { | ||
retErr := fmt.Errorf("unable to get pipeline configuration for %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusNotFound, retErr) | ||
|
||
return | ||
} | ||
} else { | ||
// some other error | ||
retErr := fmt.Errorf("unable to get pipeline for %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusInternalServerError, retErr) | ||
|
||
return | ||
} | ||
} else { | ||
l.Debugf("pipeline %s found in database", entry) | ||
|
||
config = p.GetData() | ||
} | ||
|
||
// set up compiler | ||
compiler := compiler.FromContext(c).Duplicate().WithCommit(ref).WithRepo(r).WithUser(u) | ||
|
||
// compile the pipeline | ||
pipeline, _, err := compiler.CompileLite(ctx, config, nil, true) | ||
if err != nil { | ||
retErr := fmt.Errorf("unable to compile pipeline %s: %w", entry, err) | ||
|
||
util.HandleError(c, http.StatusBadRequest, retErr) | ||
|
||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, pipeline.Deployment) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.