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