Add backend selection for agent (#463)

- add backend selection option
- by default it will auto-detect a backend
This commit is contained in:
Anbraten
2021-11-26 03:34:48 +01:00
committed by GitHub
parent 65e10d46b3
commit c1a8884d62
28 changed files with 250 additions and 174 deletions

View File

@@ -8,11 +8,11 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/woodpecker-ci/woodpecker/pipeline/backend"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
)
// returns a container configuration.
func toConfig(proc *backend.Step) *container.Config {
func toConfig(proc *types.Step) *container.Config {
config := &container.Config{
Image: proc.Image,
Labels: proc.Labels,
@@ -36,7 +36,7 @@ func toConfig(proc *backend.Step) *container.Config {
}
// returns a container host configuration.
func toHostConfig(proc *backend.Step) *container.HostConfig {
func toHostConfig(proc *types.Step) *container.HostConfig {
config := &container.HostConfig{
Resources: container.Resources{
CPUQuota: proc.CPUQuota,
@@ -146,7 +146,7 @@ func toDev(paths []string) []container.DeviceMapping {
// helper function that serializes the auth configuration as JSON
// base64 payload.
func encodeAuthToBase64(authConfig backend.Auth) (string, error) {
func encodeAuthToBase64(authConfig types.Auth) (string, error) {
buf, err := json.Marshal(authConfig)
if err != nil {
return "", err

View File

@@ -14,28 +14,38 @@ import (
"github.com/moby/term"
"github.com/rs/zerolog/log"
"github.com/woodpecker-ci/woodpecker/pipeline/backend"
backend "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
)
type engine struct {
client client.APIClient
}
// New returns a new Docker Engine using the given client.
func New(cli client.APIClient) backend.Engine {
// New returns a new Docker Engine.
func New() backend.Engine {
return &engine{
client: cli,
client: nil,
}
}
// NewEnv returns a new Docker Engine using the client connection
// environment variables.
func NewEnv() (backend.Engine, error) {
func (e *engine) Name() string {
return "docker"
}
func (e *engine) IsAvivable() bool {
_, err := os.Stat("/.dockerenv")
return os.IsNotExist(err)
}
// Load new client for Docker Engine using environment variables.
func (e *engine) Load() error {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return nil, err
return err
}
return New(cli), nil
e.client = cli
return nil
}
func (e *engine) Setup(_ context.Context, conf *backend.Config) error {