fix(push): always provide encoded empty auth config to work around panic in Docker

This commit is contained in:
Pasha Sviderski
2025-10-09 15:14:10 +10:00
parent 521ccf2026
commit 5aa85ab501
+9 -2
View File
@@ -48,9 +48,16 @@ func (cli *Client) PushImage(
) (<-chan PullPushImageMessage, error) { ) (<-chan PullPushImageMessage, error) {
if opts.RegistryAuth == "" { if opts.RegistryAuth == "" {
// Try to retrieve the authentication token for the image from the default local Docker config file. // Try to retrieve the authentication token for the image from the default local Docker config file.
if encodedAuth, err := RetrieveLocalDockerRegistryAuth(image); err == nil { encodedAuth, _ := RetrieveLocalDockerRegistryAuth(image)
opts.RegistryAuth = encodedAuth if encodedAuth == "" {
// If no credentials are found, provide an encoded empty auth config to work around the bug in Docker:
// https://github.com/moby/moby/issues/50729
var err error
if encodedAuth, err = registry.EncodeAuthConfig(registry.AuthConfig{}); err != nil {
return nil, fmt.Errorf("encode empty auth config: %w", err)
}
} }
opts.RegistryAuth = encodedAuth
} }
respBody, err := cli.ImagePush(ctx, image, opts) respBody, err := cli.ImagePush(ctx, image, opts)