Various enhancements in configuration (#1645)

- backends: move to cli flags instead of os.Getenv
- ssh: support 2fa with key and password
- allow to set grpc jwt secret (solves todo)
- allow to set default and max timeout (solves todo)

Closes https://github.com/woodpecker-ci/woodpecker/issues/896
Closes https://github.com/woodpecker-ci/woodpecker/issues/1131
This commit is contained in:
qwerty287
2023-03-19 20:24:43 +01:00
committed by GitHub
parent 56e6639396
commit f582ad3159
19 changed files with 221 additions and 104 deletions

View File

@@ -18,7 +18,6 @@ import (
"context"
"io"
"os"
"strconv"
"strings"
"github.com/docker/docker/api/types"
@@ -29,6 +28,7 @@ import (
"github.com/moby/moby/pkg/stdcopy"
"github.com/moby/term"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
backend "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
"github.com/woodpecker-ci/woodpecker/shared/utils"
@@ -41,9 +41,6 @@ type docker struct {
volumes []string
}
// make sure docker implements Engine
var _ backend.Engine = &docker{}
// New returns a new Docker Engine.
func New() backend.Engine {
return &docker{
@@ -55,7 +52,7 @@ func (e *docker) Name() string {
return "docker"
}
func (e *docker) IsAvailable() bool {
func (e *docker) IsAvailable(context.Context) bool {
if os.Getenv("DOCKER_HOST") != "" {
return true
}
@@ -64,18 +61,22 @@ func (e *docker) IsAvailable() bool {
}
// Load new client for Docker Engine using environment variables.
func (e *docker) Load() error {
cli, err := client.NewClientWithOpts(client.FromEnv)
func (e *docker) Load(ctx context.Context) error {
cl, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return err
}
e.client = cli
e.client = cl
e.enableIPv6, _ = strconv.ParseBool(os.Getenv("WOODPECKER_BACKEND_DOCKER_ENABLE_IPV6"))
c, ok := ctx.Value(backend.CliContext).(*cli.Context)
if !ok {
return backend.ErrNoCliContextFound
}
e.enableIPv6 = c.Bool("backend-docker-ipv6")
e.network = os.Getenv("WOODPECKER_BACKEND_DOCKER_NETWORK")
e.network = c.String("backend-docker-network")
volumes := strings.Split(os.Getenv("WOODPECKER_BACKEND_DOCKER_VOLUMES"), ",")
volumes := strings.Split(c.String("backend-docker-volumes"), ",")
e.volumes = make([]string, 0, len(volumes))
// Validate provided volume definitions
for _, v := range volumes {