Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 f9bc4f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
13 changes: 13 additions & 0 deletions cmd/werf/common/helm.go
Expand Up @@ -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"
Expand All @@ -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()),
Expand All @@ -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)

Expand Down
15 changes: 1 addition & 14 deletions pkg/deploy/bundles/registry/client.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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
}
Expand Down

0 comments on commit f9bc4f3

Please sign in to comment.