From f9bc4f3e543374cef76c66acc36fea55a2ca914a Mon Sep 17 00:00:00 2001 From: Timofey Kirillov Date: Wed, 24 Aug 2022 19:37:43 +0300 Subject: [PATCH] fix(helm): use same docker-config as werf uses for helm OCI regsitry related operations Signed-off-by: Timofey Kirillov --- cmd/werf/common/helm.go | 13 +++++++++++++ pkg/deploy/bundles/registry/client.go | 15 +-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/werf/common/helm.go b/cmd/werf/common/helm.go index 28d7bc4846..e289fbf9fb 100644 --- a/cmd/werf/common/helm.go +++ b/cmd/werf/common/helm.go @@ -2,8 +2,11 @@ package common import ( "context" + "path/filepath" "time" + "github.com/docker/cli/cli/config" + "github.com/docker/docker/pkg/homedir" helm_v3 "helm.sh/helm/v3/cmd/helm" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/registry" @@ -17,6 +20,7 @@ import ( func NewHelmRegistryClientHandle(ctx context.Context, commonCmdData *CmdData) (*registry.Client, error) { return registry.NewClient( + registry.ClientOptCredentialsFile(getDockerConfigCredentialsFile(*commonCmdData.DockerConfig)), registry.ClientOptDebug(logboek.Context(ctx).Debug().IsAccepted()), registry.ClientOptInsecure(*commonCmdData.InsecureHelmDependencies), registry.ClientOptWriter(logboek.Context(ctx).OutStream()), @@ -30,6 +34,7 @@ func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bun out := logboek.Context(ctx).OutStream() return bundles_registry.NewClient( + bundles_registry.ClientOptCredentialsFile(getDockerConfigCredentialsFile(*commonCmdData.DockerConfig)), bundles_registry.ClientOptDebug(debug), bundles_registry.ClientOptInsecure(insecure), bundles_registry.ClientOptSkipTlsVerify(skipTlsVerify), @@ -37,6 +42,14 @@ func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bun ) } +func getDockerConfigCredentialsFile(configDir string) string { + if configDir == "" { + return filepath.Join(homedir.Get(), ".docker", config.ConfigFileName) + } else { + return filepath.Join(configDir, config.ConfigFileName) + } +} + func NewActionConfig(ctx context.Context, kubeInitializer helm.KubeInitializer, namespace string, commonCmdData *CmdData, registryClient *registry.Client) (*action.Configuration, error) { actionConfig := new(action.Configuration) diff --git a/pkg/deploy/bundles/registry/client.go b/pkg/deploy/bundles/registry/client.go index b3b7390406..b236b5a733 100644 --- a/pkg/deploy/bundles/registry/client.go +++ b/pkg/deploy/bundles/registry/client.go @@ -24,15 +24,11 @@ import ( "io" "io/ioutil" "net/http" - "os" - "path/filepath" "sort" auth "github.com/deislabs/oras/pkg/auth/docker" "github.com/deislabs/oras/pkg/content" "github.com/deislabs/oras/pkg/oras" - "github.com/docker/cli/cli/config" - "github.com/docker/docker/pkg/homedir" "github.com/gosuri/uitable" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -60,15 +56,6 @@ type ( } ) -func getDefaultDockerConfigPath() string { - configDir := os.Getenv("DOCKER_CONFIG") - if configDir == "" { - return filepath.Join(homedir.Get(), ".docker", config.ConfigFileName) - } else { - return filepath.Join(configDir, config.ConfigFileName) - } -} - // NewClient returns a new registry client with config func NewClient(opts ...ClientOption) (*Client, error) { client := &Client{ @@ -82,7 +69,7 @@ func NewClient(opts ...ClientOption) (*Client, error) { client.credentialsFile = helmpath.CachePath("registry", CredentialsFileBasename) } if client.authorizer == nil { - authClient, err := auth.NewClient(client.credentialsFile, getDefaultDockerConfigPath()) + authClient, err := auth.NewClient(client.credentialsFile, client.credentialsFile) if err != nil { return nil, err }