0
0
forked from toolshed/abra

refactor: NewClientWithContext -> New, and use server only

This commit is contained in:
2021-09-05 00:41:31 +02:00
parent dac679db48
commit 07a43cb314
14 changed files with 55 additions and 54 deletions

View File

@ -1,3 +1,4 @@
// Package client provides Docker client initiatialisation functions.
package client
import (
@ -8,35 +9,34 @@ import (
"github.com/sirupsen/logrus"
)
func NewClientWithContext(contextName string) (*client.Client, error) {
// New initiates a new Docker client.
func New(contextName string) (*client.Client, error) {
context, err := GetContext(contextName)
if err != nil {
return nil, err
}
ctxEndpoint, err := GetContextEndpoint(context)
if err != nil {
return nil, err
}
helper := newConnectionHelper(ctxEndpoint)
httpClient := &http.Client{
// No tls
// No proxy
// No tls, no proxy
Transport: &http.Transport{
DialContext: helper.Dialer,
},
}
var clientOpts []client.Opt
clientOpts = append(clientOpts,
client.WithHTTPClient(httpClient),
client.WithHost(helper.Host),
client.WithDialContext(helper.Dialer),
)
// FIXME: Maybe don't have this variable here and load it beforehand
version := os.Getenv("DOCKER_API_VERSION")
if version != "" {
clientOpts = append(clientOpts, client.WithVersion(version))
} else {
@ -44,9 +44,9 @@ func NewClientWithContext(contextName string) (*client.Client, error) {
}
cl, err := client.NewClientWithOpts(clientOpts...)
if err != nil {
logrus.Fatalf("unable to create Docker client: %s", err)
}
return cl, nil
}