From 9ca5bf0b070250763d7e0aa74fd7e047cf236b19 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sat, 20 Jan 2024 20:06:15 +0530 Subject: [PATCH 1/2] initial changes to docker.go Signed-off-by: satyazzz123 --- testhelpers/docker.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/testhelpers/docker.go b/testhelpers/docker.go index 0779d5294..fb5becba0 100644 --- a/testhelpers/docker.go +++ b/testhelpers/docker.go @@ -2,7 +2,6 @@ package testhelpers import ( "bytes" - "context" "encoding/json" "io" "os" @@ -12,7 +11,6 @@ import ( "sync" "testing" - dockertypes "github.com/docker/docker/api/types" dockercli "github.com/docker/docker/client" "github.com/docker/docker/pkg/jsonmessage" "github.com/pkg/errors" @@ -108,16 +106,24 @@ func DockerVolumeExists(t *testing.T, volumeName string) bool { } // FIXME: re-work this function to exec the docker cli, or convert other docker helpers to using the client library. -func PushImage(dockerCli dockercli.CommonAPIClient, ref string, auth string) error { - rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: auth}) - if err != nil { - return errors.Wrap(err, "pushing image") +func PushImage(ref string, auth string) error { + // Filter out any existing DOCKER_CONFIG from the environment + filteredEnv := []string{} + for _, envVar := range os.Environ() { + if !strings.HasPrefix(envVar, "DOCKER_CONFIG=") { + filteredEnv = append(filteredEnv, envVar) + } } + // Append the new DOCKER_CONFIG to the filtered environment + cmd := exec.Command("docker", "push", ref) + cmd.Env = append(filteredEnv, "DOCKER_CONFIG="+auth) + + var stderr bytes.Buffer + cmd.Stderr = &stderr - defer rc.Close() - err = checkResponse(rc) + err := cmd.Run() if err != nil { - return errors.Wrap(err, "push response") + return errors.Wrapf(err, "error pushing image: %s", stderr.String()) } return nil From 4ce05b393cfd931d28a258c7b9940ef2c7c5e099 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sat, 20 Jan 2024 20:37:46 +0530 Subject: [PATCH 2/2] addressing the lint errors Signed-off-by: satyazzz123 --- testhelpers/docker.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testhelpers/docker.go b/testhelpers/docker.go index fb5becba0..145187a61 100644 --- a/testhelpers/docker.go +++ b/testhelpers/docker.go @@ -115,8 +115,10 @@ func PushImage(ref string, auth string) error { } } // Append the new DOCKER_CONFIG to the filtered environment + newEnv := append(filteredEnv, "DOCKER_CONFIG="+auth) + cmd := exec.Command("docker", "push", ref) - cmd.Env = append(filteredEnv, "DOCKER_CONFIG="+auth) + cmd.Env = newEnv var stderr bytes.Buffer cmd.Stderr = &stderr