From cd73bb12dd795326ca5d4da4077ede9243d734e4 Mon Sep 17 00:00:00 2001 From: Slijkhuis Date: Mon, 17 Jul 2023 09:28:18 +0200 Subject: [PATCH] fix: upgrade docker client --- container.go | 31 ++++++++++++++++--------------- docker_auth.go | 20 ++++++++++---------- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/container.go b/container.go index 77ce49e3214..ec2351ea208 100644 --- a/container.go +++ b/container.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/archive" "github.com/docker/go-connections/nat" tcexec "github.com/testcontainers/testcontainers-go/exec" @@ -59,23 +60,23 @@ type Container interface { // ImageBuildInfo defines what is needed to build an image type ImageBuildInfo interface { - GetContext() (io.Reader, error) // the path to the build context - GetDockerfile() string // the relative path to the Dockerfile, including the fileitself - ShouldPrintBuildLog() bool // allow build log to be printed to stdout - ShouldBuildImage() bool // return true if the image needs to be built - GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile - GetAuthConfigs() map[string]types.AuthConfig // return the auth configs to be able to pull from an authenticated docker registry + GetContext() (io.Reader, error) // the path to the build context + GetDockerfile() string // the relative path to the Dockerfile, including the fileitself + ShouldPrintBuildLog() bool // allow build log to be printed to stdout + ShouldBuildImage() bool // return true if the image needs to be built + GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile + GetAuthConfigs() map[string]registry.AuthConfig // return the auth configs to be able to pull from an authenticated docker registry } // FromDockerfile represents the parameters needed to build an image from a Dockerfile // rather than using a pre-built one type FromDockerfile struct { - Context string // the path to the context of of the docker build - ContextArchive io.Reader // the tar archive file to send to docker that contains the build context - Dockerfile string // the path from the context to the Dockerfile for the image, defaults to "Dockerfile" - BuildArgs map[string]*string // enable user to pass build args to docker daemon - PrintBuildLog bool // enable user to print build log - AuthConfigs map[string]types.AuthConfig // Deprecated. Testcontainers will detect registry credentials automatically. Enable auth configs to be able to pull from an authenticated docker registry + Context string // the path to the context of of the docker build + ContextArchive io.Reader // the tar archive file to send to docker that contains the build context + Dockerfile string // the path from the context to the Dockerfile for the image, defaults to "Dockerfile" + BuildArgs map[string]*string // enable user to pass build args to docker daemon + PrintBuildLog bool // enable user to print build log + AuthConfigs map[string]registry.AuthConfig // Deprecated. Testcontainers will detect registry credentials automatically. Enable auth configs to be able to pull from an authenticated docker registry } type ContainerFile struct { @@ -204,13 +205,13 @@ func (c *ContainerRequest) GetDockerfile() string { } // GetAuthConfigs returns the auth configs to be able to pull from an authenticated docker registry -func (c *ContainerRequest) GetAuthConfigs() map[string]types.AuthConfig { +func (c *ContainerRequest) GetAuthConfigs() map[string]registry.AuthConfig { images, err := testcontainersdocker.ExtractImagesFromDockerfile(filepath.Join(c.Context, c.GetDockerfile()), c.GetBuildArgs()) if err != nil { - return map[string]types.AuthConfig{} + return map[string]registry.AuthConfig{} } - authConfigs := map[string]types.AuthConfig{} + authConfigs := map[string]registry.AuthConfig{} for _, image := range images { registry, authConfig, err := DockerImageAuth(context.Background(), image) if err != nil { diff --git a/docker_auth.go b/docker_auth.go index c95f848c03d..545a47b6c25 100644 --- a/docker_auth.go +++ b/docker_auth.go @@ -7,27 +7,27 @@ import ( "os" "github.com/cpuguy83/dockercfg" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" ) // DockerImageAuth returns the auth config for the given Docker image, extracting first its Docker registry. // Finally, it will use the credential helpers to extract the information from the docker config file // for that registry, if it exists. -func DockerImageAuth(ctx context.Context, image string) (string, types.AuthConfig, error) { +func DockerImageAuth(ctx context.Context, image string) (string, registry.AuthConfig, error) { defaultRegistry := defaultRegistry(ctx) - registry := testcontainersdocker.ExtractRegistry(image, defaultRegistry) + extractedRegistry := testcontainersdocker.ExtractRegistry(image, defaultRegistry) cfgs, err := getDockerAuthConfigs() if err != nil { - return registry, types.AuthConfig{}, err + return extractedRegistry, registry.AuthConfig{}, err } - if cfg, ok := cfgs[registry]; ok { - return registry, cfg, nil + if cfg, ok := cfgs[extractedRegistry]; ok { + return extractedRegistry, cfg, nil } - return registry, types.AuthConfig{}, dockercfg.ErrCredentialsNotFound + return extractedRegistry, registry.AuthConfig{}, dockercfg.ErrCredentialsNotFound } // defaultRegistry returns the default registry to use when pulling images @@ -50,15 +50,15 @@ func defaultRegistry(ctx context.Context) string { // getDockerAuthConfigs returns a map with the auth configs from the docker config file // using the registry as the key -func getDockerAuthConfigs() (map[string]types.AuthConfig, error) { +func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) { cfg, err := getDockerConfig() if err != nil { return nil, err } - cfgs := map[string]types.AuthConfig{} + cfgs := map[string]registry.AuthConfig{} for k, v := range cfg.AuthConfigs { - ac := types.AuthConfig{ + ac := registry.AuthConfig{ Auth: v.Auth, Email: v.Email, IdentityToken: v.IdentityToken, diff --git a/go.mod b/go.mod index 617f53b616e..ea225b154ce 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/cenkalti/backoff/v4 v4.2.0 github.com/containerd/containerd v1.6.19 github.com/cpuguy83/dockercfg v0.3.1 - github.com/docker/docker v23.0.5+incompatible + github.com/docker/docker v24.0.0-rc.2.0.20230714223606-37b908aa628c+incompatible github.com/docker/go-connections v0.4.0 github.com/docker/go-units v0.5.0 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index b709f20c7e1..9771698c110 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m3 github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v23.0.5+incompatible h1:DaxtlTJjFSnLOXVNUBU1+6kXGz2lpDoEAH6QoxaSg8k= github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.0-rc.2.0.20230714223606-37b908aa628c+incompatible h1:6aC9x4c888nAxRxwyxKqzCTWZGHLTyaPBqc9yAJybzw= +github.com/docker/docker v24.0.0-rc.2.0.20230714223606-37b908aa628c+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=