From 1a39370f5b0841c5d51a5a47c95fa3828dfa65aa Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:38:55 -0300 Subject: [PATCH] fix(libstack): add missing private registry credentials BE-11388 (#143) --- pkg/libstack/compose/composeplugin.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/libstack/compose/composeplugin.go b/pkg/libstack/compose/composeplugin.go index d69bf5e14..f2d898dc2 100644 --- a/pkg/libstack/compose/composeplugin.go +++ b/pkg/libstack/compose/composeplugin.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "maps" - "os" "path/filepath" "slices" "strings" @@ -19,6 +18,7 @@ import ( "github.com/docker/cli/cli/flags" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/compose" + "github.com/docker/docker/registry" "github.com/rs/zerolog/log" ) @@ -42,14 +42,6 @@ func withCli( opts.Hosts = []string{options.Host} } - tempDir, err := os.MkdirTemp("", "docker-config") - if err != nil { - return fmt.Errorf("unable to create a temporary directory for the Docker config: %w", err) - } - defer os.RemoveAll(tempDir) - - opts.ConfigDir = tempDir - mu.Lock() if err := cli.Initialize(opts); err != nil { mu.Unlock() @@ -59,11 +51,11 @@ func withCli( defer cli.Client().Close() for _, r := range options.Registries { - creds := cli.ConfigFile().GetCredentialsStore(r.ServerAddress) - - if err := creds.Store(r); err != nil { - return fmt.Errorf("unable to store the Docker credentials: %w", err) + if r.ServerAddress == "" || r.ServerAddress == registry.DefaultNamespace { + r.ServerAddress = registry.IndexServer } + + cli.ConfigFile().AuthConfigs[r.ServerAddress] = r } return cliFn(ctx, cli)