Skip to content

Commit

Permalink
Merge branch 'main' into fix/swagger-oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Sep 6, 2024
2 parents 3fcdbcc + 372a430 commit 6fd48d4
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 62 deletions.
5 changes: 2 additions & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
{
"description": "Update docker images in go files",
"fileMatch": [
"^.*\\.go$"
"^cmd/vela-server/.+\\.go$"
],
"matchStrings": [
"\\/\\/ renovate: image=(?<depName>.*?)\\s+?.*[:|=]\\s+\"(?<currentValue>.*)\"\\,?"
"\"(?<depName>.*?):(?<currentValue>[^\"]*?)@(?<currentDigest>sha256:[a-f0-9]+)\",? // renovate: container"
],
"versioningTemplate": "docker",
"datasourceTemplate": "docker"
}
]
Expand Down
2 changes: 1 addition & 1 deletion api/types/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func testExecutor() *Executor {
{
ID: "step_github_octocat_1_clone",
Directory: "/home/github/octocat",
Image: "target/vela-git:v0.3.0",
Image: "target/vela-git-slim:v0.12.0",
Name: "clone",
Number: 2,
Pull: "always",
Expand Down
2 changes: 1 addition & 1 deletion api/types/settings/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestTypes_Compiler_String(t *testing.T) {
func testCompilerSettings() *Compiler {
cs := new(Compiler)

cs.SetCloneImage("target/vela-git:latest")
cs.SetCloneImage("target/vela-git-slim:latest")
cs.SetTemplateDepth(1)
cs.SetStarlarkExecLimit(100)

Expand Down
2 changes: 1 addition & 1 deletion api/types/settings/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func testPlatformSettings() *Platform {
// setup compiler
cs := new(Compiler)

cs.SetCloneImage("target/vela-git:latest")
cs.SetCloneImage("target/vela-git-slim:latest")
cs.SetTemplateDepth(1)
cs.SetStarlarkExecLimit(100)

Expand Down
85 changes: 62 additions & 23 deletions api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,74 @@ func PostWebhook(c *gin.Context) {
b.SetRepo(repo)
h.SetRepoID(repo.GetID())

// send API call to capture the last hook for the repo
lastHook, err := database.FromContext(c).LastHookForRepo(ctx, repo)
if err != nil {
retErr := fmt.Errorf("unable to get last hook for repo %s: %w", repo.GetFullName(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)
// number of times to retry
retryLimit := 3
// implement a loop to process asynchronous operations with a retry limit
//
// Some operations taken during the webhook workflow can lead to race conditions
// failing to successfully process the request. This logic ensures we attempt our
// best efforts to handle these cases gracefully.
for i := 0; i < retryLimit; i++ {
// check if we're on the first iteration of the loop
if i > 0 {
// incrementally sleep in between retries
time.Sleep(time.Duration(i) * time.Second)
}

h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())
// send API call to capture the last hook for the repo
lastHook, err := database.FromContext(c).LastHookForRepo(ctx, repo)
if err != nil {
// format the error message with extra information
err = fmt.Errorf("unable to get last hook for repo %s: %w", r.GetFullName(), err)

return
}
// log the error for traceability
logrus.Error(err.Error())

// set the Number field
if lastHook != nil {
h.SetNumber(
lastHook.GetNumber() + 1,
)
}
// check if the retry limit has been exceeded
if i < retryLimit {
// continue to the next iteration of the loop
continue
}

// send API call to create the webhook
h, err = database.FromContext(c).CreateHook(ctx, h)
if err != nil {
retErr := fmt.Errorf("unable to create webhook %s/%d: %w", repo.GetFullName(), h.GetNumber(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)
retErr := fmt.Errorf("%s: %w", baseErr, err)
util.HandleError(c, http.StatusInternalServerError, retErr)

h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())
h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())

return
return
}

// set the Number field
if lastHook != nil {
h.SetNumber(
lastHook.GetNumber() + 1,
)
}

// send API call to create the webhook
h, err = database.FromContext(c).CreateHook(ctx, h)
if err != nil {
// format the error message with extra information
err = fmt.Errorf("unable to create webhook %s/%d: %w", r.GetFullName(), h.GetNumber(), err)

// log the error for traceability
logrus.Error(err.Error())

// check if the retry limit has been exceeded
if i < retryLimit {
// continue to the next iteration of the loop
continue
}

retErr := fmt.Errorf("%s: %w", baseErr, err)
util.HandleError(c, http.StatusInternalServerError, retErr)

h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())

return
}
}

l.WithFields(logrus.Fields{
Expand Down
3 changes: 1 addition & 2 deletions cmd/vela-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func main() {
EnvVars: []string{"VELA_CLONE_IMAGE"},
Name: "clone-image",
Usage: "the clone image to use for the injected clone step",
// renovate: image=target/vela-git
Value: "target/vela-git:v0.8.0@sha256:02de004ae9dbf184c70039cb9ce431c31d6e7580eb9e6ec64a97ebf108aa65cb",
Value: "target/vela-git-slim:v0.12.0@sha256:533786ab3ef17c900b0105fdffbd7143d2601803f28b39e156132ad25819af0f", // renovate: container
},
&cli.StringSliceFlag{
EnvVars: []string{"VELA_REPO_ALLOWLIST"},
Expand Down
2 changes: 1 addition & 1 deletion compiler/native/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-vela/types/yaml"
)

const defaultCloneImage = "target/vela-git:latest"
const defaultCloneImage = "target/vela-git-slim:latest"

func TestNative_CloneStage(t *testing.T) {
// setup types
Expand Down
2 changes: 1 addition & 1 deletion compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ func TestNative_Compile_Clone(t *testing.T) {
ID: "step___0_clone",
Directory: "/vela/src/foo//",
Environment: cloneEnv,
Image: "target/vela-git:v0.5.1",
Image: "target/vela-git-slim:v0.12.0",
Name: "clone",
Number: 2,
Pull: "always",
Expand Down
2 changes: 1 addition & 1 deletion compiler/native/testdata/clone_replace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:

steps:
- name: clone
image: target/vela-git:v0.5.1
image: target/vela-git-slim:v0.12.0
parameters:
depth: 5
pull: always
Expand Down
14 changes: 7 additions & 7 deletions database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,8 +1804,8 @@ func testServices(t *testing.T, db Interface, resources *Resources) {
methods["ListServicesForBuild"] = true

expected := map[string]float64{
"#init": 1,
"target/vela-git:v0.3.0": 1,
"#init": 1,
"target/vela-git-slim:v0.12.0": 1,
}
images, err := db.ListServiceImageCount(context.TODO())
if err != nil {
Expand Down Expand Up @@ -1959,8 +1959,8 @@ func testSteps(t *testing.T, db Interface, resources *Resources) {
methods["ListStepsForBuild"] = true

expected := map[string]float64{
"#init": 1,
"target/vela-git:v0.3.0": 1,
"#init": 1,
"target/vela-git-slim:v0.12.0": 1,
}
images, err := db.ListStepImageCount(ctx)
if err != nil {
Expand Down Expand Up @@ -2288,7 +2288,7 @@ func testSettings(t *testing.T, db Interface, resources *Resources) {

// update the settings
for _, s := range resources.Platform {
s.SetCloneImage("target/vela-git:abc123")
s.SetCloneImage("target/vela-git-slim:abc123")
got, err := db.UpdateSettings(context.TODO(), s)
if err != nil {
t.Errorf("unable to update settings %d: %v", s.GetID(), err)
Expand Down Expand Up @@ -2757,7 +2757,7 @@ func newResources() *Resources {
serviceTwo.SetRepoID(1)
serviceTwo.SetNumber(2)
serviceTwo.SetName("clone")
serviceTwo.SetImage("target/vela-git:v0.3.0")
serviceTwo.SetImage("target/vela-git-slim:v0.12.0")
serviceTwo.SetStatus("pending")
serviceTwo.SetError("")
serviceTwo.SetExitCode(0)
Expand Down Expand Up @@ -2793,7 +2793,7 @@ func newResources() *Resources {
stepTwo.SetRepoID(1)
stepTwo.SetNumber(2)
stepTwo.SetName("clone")
stepTwo.SetImage("target/vela-git:v0.3.0")
stepTwo.SetImage("target/vela-git-slim:v0.12.0")
stepTwo.SetStage("init")
stepTwo.SetStatus("pending")
stepTwo.SetError("")
Expand Down
4 changes: 2 additions & 2 deletions database/settings/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestSettings_Engine_CreateSettings(t *testing.T) {
// setup types
_settings := testSettings()
_settings.SetID(1)
_settings.SetCloneImage("target/vela-git:latest")
_settings.SetCloneImage("target/vela-git-slim:latest")
_settings.SetTemplateDepth(10)
_settings.SetStarlarkExecLimit(100)
_settings.SetRoutes([]string{"vela"})
Expand All @@ -32,7 +32,7 @@ func TestSettings_Engine_CreateSettings(t *testing.T) {

// ensure the mock expects the query
_mock.ExpectQuery(`INSERT INTO "settings" ("compiler","queue","repo_allowlist","schedule_allowlist","created_at","updated_at","updated_by","id") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"`).
WithArgs(`{"clone_image":{"String":"target/vela-git:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
WithArgs(`{"clone_image":{"String":"target/vela-git-slim:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
`{"routes":["vela"]}`, `{"octocat/hello-world"}`, `{"*"}`, 1, 1, ``, 1).
WillReturnRows(_rows)

Expand Down
4 changes: 2 additions & 2 deletions database/settings/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestSettings_Engine_GetSettings(t *testing.T) {
// setup types
_settings := testSettings()
_settings.SetID(1)
_settings.SetCloneImage("target/vela-git:latest")
_settings.SetCloneImage("target/vela-git-slim:latest")
_settings.SetTemplateDepth(10)
_settings.SetStarlarkExecLimit(100)
_settings.SetRoutes([]string{"vela"})
Expand All @@ -32,7 +32,7 @@ func TestSettings_Engine_GetSettings(t *testing.T) {
// create expected result in mock
_rows := sqlmock.NewRows(
[]string{"id", "compiler", "queue", "repo_allowlist", "schedule_allowlist", "created_at", "updated_at", "updated_by"}).
AddRow(1, `{"clone_image":{"String":"target/vela-git:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
AddRow(1, `{"clone_image":{"String":"target/vela-git-slim:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
`{"routes":["vela"]}`, `{"octocat/hello-world"}`, `{"*"}`, 1, 1, `octocat`)

// ensure the mock expects the query
Expand Down
4 changes: 2 additions & 2 deletions database/settings/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestSettings_Engine_UpdateSettings(t *testing.T) {
// setup types
_settings := testSettings()
_settings.SetID(1)
_settings.SetCloneImage("target/vela-git:latest")
_settings.SetCloneImage("target/vela-git-slim:latest")
_settings.SetTemplateDepth(10)
_settings.SetStarlarkExecLimit(100)
_settings.SetRoutes([]string{"vela", "large"})
Expand All @@ -31,7 +31,7 @@ func TestSettings_Engine_UpdateSettings(t *testing.T) {

// ensure the mock expects the query
_mock.ExpectExec(`UPDATE "settings" SET "compiler"=$1,"queue"=$2,"repo_allowlist"=$3,"schedule_allowlist"=$4,"created_at"=$5,"updated_at"=$6,"updated_by"=$7 WHERE "id" = $8`).
WithArgs(`{"clone_image":{"String":"target/vela-git:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
WithArgs(`{"clone_image":{"String":"target/vela-git-slim:latest","Valid":true},"template_depth":{"Int64":10,"Valid":true},"starlark_exec_limit":{"Int64":100,"Valid":true}}`,
`{"routes":["vela","large"]}`, `{"octocat/hello-world"}`, `{"*"}`, 1, testutils.AnyArgument{}, "octocat", 1).
WillReturnResult(sqlmock.NewResult(1, 1))

Expand Down
12 changes: 6 additions & 6 deletions database/types/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestTypes_Platform_ToAPI(t *testing.T) {
want.SetUpdatedBy("")

want.Compiler = new(api.Compiler)
want.SetCloneImage("target/vela-git:latest")
want.SetCloneImage("target/vela-git-slim:latest")
want.SetTemplateDepth(10)
want.SetStarlarkExecLimit(100)

Expand Down Expand Up @@ -98,7 +98,7 @@ func TestTypes_Platform_Validate(t *testing.T) {
settings: &Platform{
ID: sql.NullInt64{Int64: 1, Valid: true},
Compiler: Compiler{
CloneImage: sql.NullString{String: "target/vela-git:latest", Valid: true},
CloneImage: sql.NullString{String: "target/vela-git-slim:latest", Valid: true},
StarlarkExecLimit: sql.NullInt64{Int64: 100, Valid: true},
},
},
Expand All @@ -108,7 +108,7 @@ func TestTypes_Platform_Validate(t *testing.T) {
settings: &Platform{
ID: sql.NullInt64{Int64: 1, Valid: true},
Compiler: Compiler{
CloneImage: sql.NullString{String: "target/vela-git:latest", Valid: true},
CloneImage: sql.NullString{String: "target/vela-git-slim:latest", Valid: true},
TemplateDepth: sql.NullInt64{Int64: 10, Valid: true},
},
},
Expand All @@ -118,7 +118,7 @@ func TestTypes_Platform_Validate(t *testing.T) {
settings: &Platform{
ID: sql.NullInt64{Int64: 1, Valid: true},
Compiler: Compiler{
CloneImage: sql.NullString{String: "target/vela-git:latest", Valid: true},
CloneImage: sql.NullString{String: "target/vela-git-slim:latest", Valid: true},
TemplateDepth: sql.NullInt64{Int64: 10, Valid: true},
StarlarkExecLimit: sql.NullInt64{Int64: 100, Valid: true},
},
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestTypes_Platform_PlatformFromAPI(t *testing.T) {
s.SetUpdatedBy("")

s.Compiler = new(api.Compiler)
s.SetCloneImage("target/vela-git:latest")
s.SetCloneImage("target/vela-git-slim:latest")
s.SetTemplateDepth(10)
s.SetStarlarkExecLimit(100)

Expand All @@ -179,7 +179,7 @@ func testPlatform() *Platform {
return &Platform{
ID: sql.NullInt64{Int64: 1, Valid: true},
Compiler: Compiler{
CloneImage: sql.NullString{String: "target/vela-git:latest", Valid: true},
CloneImage: sql.NullString{String: "target/vela-git-slim:latest", Valid: true},
TemplateDepth: sql.NullInt64{Int64: 10, Valid: true},
StarlarkExecLimit: sql.NullInt64{Int64: 100, Valid: true},
},
Expand Down
6 changes: 3 additions & 3 deletions mock/server/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
{
"id": 1,
"compiler": {
"clone_image": "target/vela-git",
"clone_image": "target/vela-git-slim",
"template_depth": 3,
"starlark_exec_limit": 100
},
Expand All @@ -42,7 +42,7 @@ const (
{
"id": 1,
"compiler": {
"clone_image": "target/vela-git:latest",
"clone_image": "target/vela-git-slim:latest",
"template_depth": 5,
"starlark_exec_limit": 123
},
Expand All @@ -67,7 +67,7 @@ const (
{
"id": 1,
"compiler": {
"clone_image": "target/vela-git:latest",
"clone_image": "target/vela-git-slim:latest",
"template_depth": 5,
"starlark_exec_limit": 123
},
Expand Down
4 changes: 2 additions & 2 deletions router/middleware/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

func TestMiddleware_CompilerNative(t *testing.T) {
// setup types
defaultCloneImage := "target/vela-git"
wantCloneImage := "target/vela-git:latest"
defaultCloneImage := "target/vela-git-slim"
wantCloneImage := "target/vela-git-slim:latest"

set := flag.NewFlagSet("", flag.ExitOnError)
set.String("clone-image", defaultCloneImage, "doc")
Expand Down
2 changes: 1 addition & 1 deletion router/middleware/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestPipeline_Establish_NoPipeline(t *testing.T) {
}

set := flag.NewFlagSet("test", 0)
set.String("clone-image", "target/vela-git:latest", "doc")
set.String("clone-image", "target/vela-git-slim:latest", "doc")

comp, err := native.FromCLIContext(cli.NewContext(nil, set, nil))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions router/middleware/settings/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestSettings_FromContext(t *testing.T) {
// setup types
num := int64(1)
cloneImage := "target/vela-git"
cloneImage := "target/vela-git-slim"

cs := settings.Compiler{
CloneImage: &cloneImage,
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestSettings_FromContext_Empty(t *testing.T) {
func TestSettings_ToContext(t *testing.T) {
// setup types
num := int64(1)
cloneImage := "target/vela-git"
cloneImage := "target/vela-git-slim"

cs := settings.Compiler{
CloneImage: &cloneImage,
Expand Down
Loading

0 comments on commit 6fd48d4

Please sign in to comment.