-
-
Notifications
You must be signed in to change notification settings - Fork 359
/
backend.go
50 lines (41 loc) · 1.09 KB
/
backend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package backend
import (
"context"
"fmt"
"go.woodpecker-ci.org/woodpecker/pipeline/backend/docker"
"go.woodpecker-ci.org/woodpecker/pipeline/backend/kubernetes"
"go.woodpecker-ci.org/woodpecker/pipeline/backend/local"
"go.woodpecker-ci.org/woodpecker/pipeline/backend/ssh"
"go.woodpecker-ci.org/woodpecker/pipeline/backend/types"
)
var (
enginesByName map[string]types.Engine
engines []types.Engine
)
func Init(ctx context.Context) {
engines = []types.Engine{
docker.New(),
local.New(),
ssh.New(),
kubernetes.New(ctx),
}
enginesByName = make(map[string]types.Engine)
for _, engine := range engines {
enginesByName[engine.Name()] = engine
}
}
func FindEngine(ctx context.Context, engineName string) (types.Engine, error) {
if engineName == "auto-detect" {
for _, engine := range engines {
if engine.IsAvailable(ctx) {
return engine, nil
}
}
return nil, fmt.Errorf("can't detect an available backend engine")
}
engine, ok := enginesByName[engineName]
if !ok {
return nil, fmt.Errorf("backend engine '%s' not found", engineName)
}
return engine, nil
}