Skip to content

Commit

Permalink
refactor: remove types dependency (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Oct 22, 2024
1 parent 0e10f28 commit 3db6801
Show file tree
Hide file tree
Showing 75 changed files with 122 additions and 233 deletions.
6 changes: 3 additions & 3 deletions api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func GetBuild(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to read build: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func CancelBuild(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to cancel build: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down
13 changes: 6 additions & 7 deletions api/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/gin-gonic/gin"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/types"
"github.com/go-vela/worker/executor"
exec "github.com/go-vela/worker/router/middleware/executor"
)
Expand Down Expand Up @@ -57,7 +56,7 @@ func GetExecutor(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to retrieve build: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand All @@ -67,7 +66,7 @@ func GetExecutor(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to retrieve pipeline: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down Expand Up @@ -104,7 +103,7 @@ func GetExecutors(c *gin.Context) {
if value == nil {
msg := "no running executors found"

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand All @@ -114,7 +113,7 @@ func GetExecutors(c *gin.Context) {
if !ok {
msg := "unable to get executors"

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand All @@ -136,7 +135,7 @@ func GetExecutors(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to retrieve build: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand All @@ -146,7 +145,7 @@ func GetExecutors(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to retrieve pipeline: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down
4 changes: 2 additions & 2 deletions api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func GetPipeline(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to read pipeline: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down
4 changes: 2 additions & 2 deletions api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func GetRepo(c *gin.Context) {
if err != nil {
msg := fmt.Errorf("unable to read build: %w", err).Error()

c.AbortWithStatusJSON(http.StatusInternalServerError, types.Error{Message: &msg})
c.AbortWithStatusJSON(http.StatusInternalServerError, api.Error{Message: &msg})

return
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/queue/models"
"github.com/go-vela/types"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/worker/executor"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/version"
Expand All @@ -36,7 +34,7 @@ func (w *Worker) exec(index int, config *api.Worker) error {

var (
execBuildClient *vela.Client
execBuildExecutable *library.BuildExecutable
execBuildExecutable *api.BuildExecutable
p *pipeline.Build
item *models.Item
retries = 3
Expand Down Expand Up @@ -188,7 +186,7 @@ func (w *Worker) exec(index int, config *api.Worker) error {
// If the ItemVersion is older or newer than what we expect, then it might
// not be safe to process the build. Fail the build and loop to the next item.
// TODO: Ask the server to re-compile and requeue the build instead of failing it.
logrus.Errorf("Failing stale queued build due to wrong item version: want %d, got %d", types.ItemVersion, item.ItemVersion)
logrus.Errorf("Failing stale queued build due to wrong item version: want %d, got %d", models.ItemVersion, item.ItemVersion)

build := item.Build
build.SetError("Unable to process stale build (queued before Vela upgrade/downgrade).")
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"golang.org/x/sync/errgroup"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/queue"
"github.com/go-vela/types/constants"
)

// operate is a helper function to initiate all
Expand Down
5 changes: 2 additions & 3 deletions cmd/vela-worker/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"github.com/sirupsen/logrus"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/server/constants"
)

// checkIn is a helper function to phone home to the server.
Expand All @@ -21,7 +20,7 @@ func (w *Worker) checkIn(config *api.Worker) (bool, string, error) {
logrus.Infof("retrieving worker %s from the server", config.GetHostname())

var (
tkn *library.Token
tkn *api.Token
retries = 3
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/queue"
"github.com/go-vela/types/constants"
"github.com/go-vela/worker/executor"
"github.com/go-vela/worker/runtime"
)
Expand Down
2 changes: 1 addition & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/sirupsen/logrus"

"github.com/go-vela/types/constants"
"github.com/go-vela/server/constants"
)

// New creates and returns a Vela engine capable of
Expand Down
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/constants"
"github.com/go-vela/worker/executor/linux"
"github.com/go-vela/worker/executor/local"
"github.com/go-vela/worker/runtime/docker"
Expand Down
2 changes: 1 addition & 1 deletion executor/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/urfave/cli/v2"

"github.com/go-vela/types/constants"
"github.com/go-vela/server/constants"
)

// Flags represents all supported command line
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/types/constants"
"github.com/go-vela/server/constants"
"github.com/go-vela/worker/internal/service"
"github.com/go-vela/worker/internal/step"
)
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"testing"

"github.com/go-vela/types/constants"
"github.com/go-vela/server/constants"
)

func TestLinux_GetBuild(t *testing.T) {
Expand Down
35 changes: 2 additions & 33 deletions executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/server/constants"
"github.com/go-vela/worker/internal/build"
context2 "github.com/go-vela/worker/internal/context"
"github.com/go-vela/worker/internal/image"
Expand Down Expand Up @@ -121,8 +120,6 @@ func (c *client) PlanBuild(ctx context.Context) error {
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Inspecting runtime network...\n"))

// inspect the runtime network for the pipeline
Expand All @@ -133,8 +130,6 @@ func (c *client) PlanBuild(ctx context.Context) error {
}

// update the init log with network information
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(network)

c.Logger.Info("creating volume")
Expand All @@ -145,8 +140,6 @@ func (c *client) PlanBuild(ctx context.Context) error {
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Inspecting runtime volume...\n"))

// inspect the runtime volume for the pipeline
Expand All @@ -157,13 +150,9 @@ func (c *client) PlanBuild(ctx context.Context) error {
}

// update the init log with volume information
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(volume)

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Preparing secrets...\n"))

// iterate through each secret provided in the pipeline
Expand Down Expand Up @@ -262,8 +251,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}()

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Preparing service images...\n"))

// create the services for the pipeline
Expand Down Expand Up @@ -291,14 +278,10 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}

// update the init log with service image info
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(image)
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Preparing stage images...\n"))

// create the stages for the pipeline
Expand All @@ -319,8 +302,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Preparing step images...\n"))

// create the steps for the pipeline
Expand Down Expand Up @@ -349,14 +330,10 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}

// update the init log with step image info
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(image)
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Preparing secret images...\n"))

// create the secrets for the pipeline
Expand Down Expand Up @@ -394,8 +371,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}

// update the init log with secret image info
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(image)
}

Expand All @@ -415,8 +390,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
if len(buildOutput) > 0 {
// update the init log with progress
// (an empty value allows the runtime to opt out of providing this)
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData(buildOutput)
}

Expand All @@ -427,8 +400,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}

// update the init log with progress
//
// https://pkg.go.dev/github.com/go-vela/types/library#Log.AppendData
_log.AppendData([]byte("> Executing secret images...\n"))

return c.err
Expand Down Expand Up @@ -698,7 +669,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
//
//nolint:funlen // explanation takes up a lot of lines
func loadLazySecrets(c *client, _step *pipeline.Container) error {
_log := new(library.Log)
_log := new(api.Log)

lazySecrets := make(map[string]*api.Secret)
lazyNoSubSecrets := make(map[string]*api.Secret)
Expand Down Expand Up @@ -836,8 +807,6 @@ func loadLazySecrets(c *client, _step *pipeline.Container) error {

c.Logger.Debug("substituting container configuration after lazy loaded secret injection")
// substitute container configuration
//
// https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.Substitute
err = tmpStep.Substitute()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/native"
"github.com/go-vela/server/compiler/types/pipeline"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/constants"
"github.com/go-vela/worker/internal/message"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"
Expand Down
Loading

0 comments on commit 3db6801

Please sign in to comment.