Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXME: re-worked PushImage function to exec the docker cli, or convert other docker helpers to using the client library. #1274

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions testhelpers/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import (
"bytes"
"context"
"encoding/json"
"io"
"os"
Expand All @@ -12,7 +11,6 @@
"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"
Expand Down Expand Up @@ -108,16 +106,26 @@
}

// 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
newEnv := append(filteredEnv, "DOCKER_CONFIG="+auth)

Check failure on line 118 in testhelpers/docker.go

View workflow job for this annotation

GitHub Actions / test-windows

appendAssign: append result not assigned to the same slice (gocritic)

Check failure on line 118 in testhelpers/docker.go

View workflow job for this annotation

GitHub Actions / test-linux-amd64

appendAssign: append result not assigned to the same slice (gocritic)

Check failure on line 118 in testhelpers/docker.go

View workflow job for this annotation

GitHub Actions / test-linux-arm64

appendAssign: append result not assigned to the same slice (gocritic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think auth here is a JSON encoded string, whereas docker expects the location of a directory containing a config.json file. If you look further up to where auth is constructed it should be possible to find that directory.


cmd := exec.Command("docker", "push", ref)
cmd.Env = newEnv

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
Expand Down
Loading