This repository has been archived on 2021-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
go-abra/client/client.go

46 lines
925 B
Go
Raw Normal View History

package client
import (
"fmt"
"net/http"
"os"
"github.com/docker/docker/client"
)
func NewClientWithContext(contextURL string) *client.Client {
helper := newConnectionHelper(contextURL)
httpClient := &http.Client{
// 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 {
clientOpts = append(clientOpts, client.WithAPIVersionNegotiation())
}
cl, err := client.NewClientWithOpts(clientOpts...)
if err != nil {
fmt.Println("Unable to create docker client")
panic(err)
}
return cl
}