Skip to content

Commit

Permalink
docker: Add version negotation to docker init. Fixes #931 (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks authored Jan 7, 2019
1 parent 377b963 commit e27d75a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func DefaultDockerClient(ctx context.Context, env k8s.Env) (*DockerCli, error) {
envFunc = func(key string) string { return envMap[key] }
}

opts, err := CreateClientOpts(envFunc)
opts, err := CreateClientOpts(ctx, envFunc)
if err != nil {
return nil, errors.Wrap(err, "newDockerClient")
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func SupportsBuildkit(v types.Version) bool {
// DOCKER_API_VERSION to set the version of the API to reach, leave empty for latest.
// DOCKER_CERT_PATH to load the TLS certificates from.
// DOCKER_TLS_VERIFY to enable or disable TLS verification, off by default.
func CreateClientOpts(env func(string) string) ([]func(client *client.Client) error, error) {
func CreateClientOpts(ctx context.Context, env func(string) string) ([]func(client *client.Client) error, error) {
result := make([]func(client *client.Client) error, 0)

if dockerCertPath := env("DOCKER_CERT_PATH"); dockerCertPath != "" {
Expand Down Expand Up @@ -183,12 +183,21 @@ func CreateClientOpts(env func(string) string) ([]func(client *client.Client) er
if version := env("DOCKER_API_VERSION"); version != "" {
result = append(result, client.WithVersion(version))
} else {
result = append(result, client.WithVersion(defaultVersion))
// NegotateAPIVersion makes the docker client negotiate down to a lower version
// if 'defaultVersion' is newer than the server version.
result = append(result, client.WithVersion(defaultVersion), NegotiateAPIVersion(ctx))
}

return result, nil
}

func NegotiateAPIVersion(ctx context.Context) func(client *client.Client) error {
return func(client *client.Client) error {
client.NegotiateAPIVersion(ctx)
return nil
}
}

func (d *DockerCli) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
requestedBuildkit := options.Version == types.BuilderBuildKit
if requestedBuildkit && !d.supportsBuildkit {
Expand Down

0 comments on commit e27d75a

Please sign in to comment.