mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 12:59:27 +00:00
Add backend selection for agent (#463)
- add backend selection option - by default it will auto-detect a backend
This commit is contained in:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user