Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pkg/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ type Client interface {

type dockerClient struct {
apiClient func() client.APIClient
cli command.Cli
}

func NewClient(cli command.Cli) Client {
return &dockerClient{
cli: cli,
apiClient: sync.OnceValue(func() client.APIClient {
_ = cli.Apply(func(cli *command.DockerCli) error {
if mobyClient, ok := cli.Client().(*client.Client); ok {
Expand Down
9 changes: 9 additions & 0 deletions pkg/docker/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

cerrdefs "github.com/containerd/errdefs"
"github.com/distribution/reference"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/image"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -78,6 +79,14 @@ func (c *dockerClient) pullImage(ctx context.Context, imageName string, registry
var pullOptions image.PullOptions
if strings.HasPrefix(ref.Name(), "docker.io/") {
pullOptions.RegistryAuth = registryAuthFn()
} else if c.cli != nil {
// For non-Hub registries (e.g. dhi.io), resolve credentials from the
// Docker CLI credential store. This uses the same auth path as
// "docker pull" and works with any configured credential helper.
encodedAuth, err := command.RetrieveAuthTokenFromImage(c.cli.ConfigFile(), imageName)
if err == nil {
pullOptions.RegistryAuth = encodedAuth
}
}

response, err := c.apiClient().ImagePull(ctx, imageName, pullOptions)
Expand Down
Loading