mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 10:07:21 +02:00
parent
0b91317cde
commit
6785806873
@ -213,13 +213,12 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
|
||||
}
|
||||
|
||||
backendCtx := context.WithValue(c.Context, backendTypes.CliContext, c)
|
||||
backend.Init([]backendTypes.Backend{
|
||||
backends := []backendTypes.Backend{
|
||||
kubernetes.New(),
|
||||
docker.New(),
|
||||
local.New(),
|
||||
kubernetes.New(),
|
||||
})
|
||||
|
||||
backendEngine, err := backend.FindBackend(backendCtx, c.String("backend-engine"))
|
||||
}
|
||||
backendEngine, err := backend.FindBackend(backendCtx, backends, c.String("backend-engine"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ import (
|
||||
"go.woodpecker-ci.org/woodpecker/v2/version"
|
||||
)
|
||||
|
||||
func run(c *cli.Context, backendEngines []types.Backend) error {
|
||||
func run(c *cli.Context, backends []types.Backend) error {
|
||||
agentConfigPath := c.String("agent-config")
|
||||
hostname := c.String("hostname")
|
||||
if len(hostname) == 0 {
|
||||
@ -153,9 +153,8 @@ func run(c *cli.Context, backendEngines []types.Backend) error {
|
||||
|
||||
// new engine
|
||||
backendCtx := context.WithValue(ctx, types.CliContext, c)
|
||||
backend.Init(backendEngines)
|
||||
backendName := c.String("backend-engine")
|
||||
backendEngine, err := backend.FindBackend(backendCtx, backendName)
|
||||
backendEngine, err := backend.FindBackend(backendCtx, backends, backendName)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("cannot find backend engine '%s'", backendName)
|
||||
return err
|
||||
|
@ -24,8 +24,8 @@ import (
|
||||
|
||||
func main() {
|
||||
core.RunAgent([]backendTypes.Backend{
|
||||
kubernetes.New(),
|
||||
docker.New(),
|
||||
local.New(),
|
||||
kubernetes.New(),
|
||||
})
|
||||
}
|
||||
|
@ -21,19 +21,7 @@ import (
|
||||
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
||||
)
|
||||
|
||||
var (
|
||||
backendsByName map[string]types.Backend
|
||||
backends []types.Backend
|
||||
)
|
||||
|
||||
func Init(backends []types.Backend) {
|
||||
backendsByName = make(map[string]types.Backend)
|
||||
for _, engine := range backends {
|
||||
backendsByName[engine.Name()] = engine
|
||||
}
|
||||
}
|
||||
|
||||
func FindBackend(ctx context.Context, backendName string) (types.Backend, error) {
|
||||
func FindBackend(ctx context.Context, backends []types.Backend, backendName string) (types.Backend, error) {
|
||||
if backendName == "auto-detect" {
|
||||
for _, engine := range backends {
|
||||
if engine.IsAvailable(ctx) {
|
||||
@ -44,10 +32,11 @@ func FindBackend(ctx context.Context, backendName string) (types.Backend, error)
|
||||
return nil, fmt.Errorf("can't detect an available backend engine")
|
||||
}
|
||||
|
||||
engine, ok := backendsByName[backendName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("backend engine '%s' not found", backendName)
|
||||
for _, engine := range backends {
|
||||
if engine.Name() == backendName {
|
||||
return engine, nil
|
||||
}
|
||||
}
|
||||
|
||||
return engine, nil
|
||||
return nil, fmt.Errorf("backend engine '%s' not found", backendName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user