From 31ecf0f3c3cd4756213a473c1a649dd83272656f Mon Sep 17 00:00:00 2001 From: Tedi Mitiku Date: Tue, 29 Oct 2024 14:09:23 +0900 Subject: [PATCH] return empty auth config if no config.json found --- .../backend_impls/docker/docker_manager/docker_auth.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth.go index 9fdae1317a..2d7caf244b 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "encoding/json" + "errors" "fmt" "os" "os/exec" @@ -35,13 +36,16 @@ func loadDockerAuth() (RegistryAuthConfig, error) { } file, err := os.ReadFile(configFilePath) - if err != nil { - return RegistryAuthConfig{}, stacktrace.Propagate(err, "error reading Docker config file") + if errors.Is(err, os.ErrNotExist) { + // If the auth config doesn't exist, return an empty auth config + return RegistryAuthConfig{}, nil + } else if err != nil { + return RegistryAuthConfig{}, stacktrace.Propagate(err, "error reading Docker config file at '%s'", configFilePath) } var authConfig RegistryAuthConfig if err := json.Unmarshal(file, &authConfig); err != nil { - return RegistryAuthConfig{}, stacktrace.Propagate(err, "error unmarshalling Docker config file") + return RegistryAuthConfig{}, stacktrace.Propagate(err, "error unmarshalling Docker config file at '%s'", configFilePath) } return authConfig, nil