Skip to content
Permalink
Browse files
fix(helm): use same docker-config as werf uses for helm OCI regsitry …
…related operations

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Aug 25, 2022
1 parent 1a780c5 commit f9bc4f3e543374cef76c66acc36fea55a2ca914a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
@@ -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,13 +34,22 @@ 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),
bundles_registry.ClientOptWriter(out),
)
}

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)

@@ -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
}

0 comments on commit f9bc4f3

Please sign in to comment.