Skip to content

Commit

Permalink
Merge branch 'main' into feat/otel-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Sep 9, 2024
2 parents e945cd8 + e0c2f7e commit 3cb9bb3
Show file tree
Hide file tree
Showing 25 changed files with 115 additions and 76 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 .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: create spec
run: |
sudo make spec-install
make spec-install
make spec
- name: upload spec
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
- name: validate spec
run: |
sudo make spec-install
make spec-install
make spec
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,10 @@ spec-install:
$(if $(shell command -v apt-get 2> /dev/null),,$(error 'apt-get' not found - install jq, sponge, and go-swagger manually))
@echo
@echo "### Installing utilities (jq and sponge)"
@apt-get update
@apt-get install -y jq moreutils
@echo "### Downloading and installing go-swagger"
@curl -o /usr/local/bin/swagger -L "https://github.com/go-swagger/go-swagger/releases/download/v0.30.2/swagger_linux_amd64"
@chmod +x /usr/local/bin/swagger
@sudo apt-get update
@sudo apt-get install -y jq moreutils
@echo "### Installing go-swagger"
@go install github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0

# The `spec-gen` target is intended to create an api-spec
# using go-swagger (https://goswagger.io)
Expand Down
2 changes: 0 additions & 2 deletions api/jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
// produces:
// - application/json
// parameters:
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully retrieved the Vela JWKS
Expand Down
2 changes: 0 additions & 2 deletions api/oi_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
// produces:
// - application/json
// parameters:
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully retrieved the Vela OpenID Configuration
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
13 changes: 10 additions & 3 deletions api/types/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package types

import (
"github.com/golang-jwt/jwt/v5"
"github.com/lestrrat-go/jwx/v2/jwk"
)

// OpenIDConfig is a struct that represents the OpenID Connect configuration.
Expand Down Expand Up @@ -40,9 +39,17 @@ type OpenIDClaims struct {
jwt.RegisteredClaims
}

// JWKSet is a wrapper of lestrrat-go/jwx/jwk.Set for API Swagger gen.
// JWKSet exists solely to provide proper swagger documentation.
// It is not otherwise used in code.
//
// swagger:model JWKSet
type JWKSet struct {
jwk.Set
Keys []JWK `json:"keys"`
}

type JWK struct {
Kty string `json:"kty"`
Kid string `json:"kid"`
E string `json:"e"`
N string `json:"n"`
}
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 @@ -95,8 +95,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 @@ -1806,8 +1806,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 @@ -1961,8 +1961,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 @@ -2290,7 +2290,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 @@ -2759,7 +2759,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 @@ -2795,7 +2795,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
Loading

0 comments on commit 3cb9bb3

Please sign in to comment.