mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 08:31:57 +00:00
Make sure we dont have hidden options for backend and pipeline compiler (#2123)
move options based on **os.Getenv** into flags --------- *Sponsored by Kithara Software GmbH*
This commit is contained in:
@@ -17,13 +17,16 @@ package docker
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/go-connections/tlsconfig"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/pkg/jsonmessage"
|
||||
"github.com/moby/moby/pkg/stdcopy"
|
||||
@@ -67,20 +70,56 @@ func (e *docker) IsAvailable(context.Context) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func httpClientOfOpts(dockerCertPath string, verifyTLS bool) *http.Client {
|
||||
if dockerCertPath == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
options := tlsconfig.Options{
|
||||
CAFile: filepath.Join(dockerCertPath, "ca.pem"),
|
||||
CertFile: filepath.Join(dockerCertPath, "cert.pem"),
|
||||
KeyFile: filepath.Join(dockerCertPath, "key.pem"),
|
||||
InsecureSkipVerify: !verifyTLS,
|
||||
}
|
||||
tlsConf, err := tlsconfig.Client(options)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not create http client out of docker backend options")
|
||||
return nil
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{TLSClientConfig: tlsConf},
|
||||
CheckRedirect: client.CheckRedirect,
|
||||
}
|
||||
}
|
||||
|
||||
// Load new client for Docker Engine using environment variables.
|
||||
func (e *docker) Load(ctx context.Context) error {
|
||||
cl, err := client.NewClientWithOpts(client.FromEnv)
|
||||
c, ok := ctx.Value(backend.CliContext).(*cli.Context)
|
||||
if !ok {
|
||||
return backend.ErrNoCliContextFound
|
||||
}
|
||||
|
||||
var dockerClientOpts []client.Opt
|
||||
if httpClient := httpClientOfOpts(c.String("backend-docker-cert"), c.Bool("backend-docker-tls-verify")); httpClient != nil {
|
||||
dockerClientOpts = append(dockerClientOpts, client.WithHTTPClient(httpClient))
|
||||
}
|
||||
if dockerHost := c.String("backend-docker-host"); dockerHost != "" {
|
||||
dockerClientOpts = append(dockerClientOpts, client.WithHost(dockerHost))
|
||||
}
|
||||
if dockerAPIVersion := c.String("backend-docker-api-version"); dockerAPIVersion != "" {
|
||||
dockerClientOpts = append(dockerClientOpts, client.WithVersion(dockerAPIVersion))
|
||||
} else {
|
||||
dockerClientOpts = append(dockerClientOpts, client.WithAPIVersionNegotiation())
|
||||
}
|
||||
|
||||
cl, err := client.NewClientWithOpts(dockerClientOpts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e.client = cl
|
||||
|
||||
c, ok := ctx.Value(backend.CliContext).(*cli.Context)
|
||||
if !ok {
|
||||
return backend.ErrNoCliContextFound
|
||||
}
|
||||
e.enableIPv6 = c.Bool("backend-docker-ipv6")
|
||||
|
||||
e.network = c.String("backend-docker-network")
|
||||
|
||||
volumes := strings.Split(c.String("backend-docker-volumes"), ",")
|
||||
|
Reference in New Issue
Block a user