Skip to content

Commit

Permalink
feat: adding support to push multiple chart from specific directory
Browse files Browse the repository at this point in the history
  • Loading branch information
C123R committed Apr 11, 2020
1 parent e584a34 commit 80e2094
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 27 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ helm plugin install https://github.com/C123R/helm-blob.git --version 0.1.0
helm blob push mychart.tar.gz azurehelm
```

You can also push multiple charts from specific directory:

```sh
helm blob push charts/ gcsblob azurehelm
```

- ### Updating Helm cache (Required after pushing new chart)

```sh
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.0
v0.3.0
23 changes: 21 additions & 2 deletions cmd/helm-blob/push.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"os"
"path/filepath"

"github.com/C123R/helm-blob/pkg/repo"
"github.com/spf13/cobra"
)
Expand All @@ -18,13 +21,29 @@ with remote index file.
`,
Example: `helm blob push sample-chart.tgz sample-repository`,
RunE: func(cmd *cobra.Command, args []string) error {
chart, repositoryName := args[0], args[1]
var charts []string
chartpath, repositoryName := args[0], args[1]
r, err := repo.NewRepoByName(repositoryName)
if err != nil {
return err
}
if err = r.Push(chart, force); err != nil {
f, err := os.Stat(chartpath)
switch {
case err != nil:
return err
case f.IsDir():
charts, err = filepath.Glob(filepath.Join(chartpath, "*.tgz"))
if err != nil {
return err
}
default:
charts = append(charts, chartpath)
}

for _, chart := range charts {
if err = r.Push(chart, force); err != nil {
return err
}
}
return nil
},
Expand Down
10 changes: 1 addition & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ go 1.13

require (
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/aws/aws-sdk-go v1.20.6 // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/go-cmp v0.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/cobra v0.0.7
gocloud.dev v0.19.0
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 // indirect
google.golang.org/grpc v1.27.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
k8s.io/client-go v0.17.2 // indirect
k8s.io/helm v2.16.5+incompatible
helm.sh/helm/v3 v3.1.2
sigs.k8s.io/yaml v1.2.0
)

Expand Down
304 changes: 300 additions & 4 deletions go.sum

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions pkg/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"github.com/C123R/helm-blob/pkg/blob"
"sigs.k8s.io/yaml"

"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm/environment"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/provenance"
helmrepo "k8s.io/helm/pkg/repo"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/helmpath"
"helm.sh/helm/v3/pkg/provenance"
helmrepo "helm.sh/helm/v3/pkg/repo"
)

type IndexFile helmrepo.IndexFile
Expand Down Expand Up @@ -81,7 +80,7 @@ func (r Repo) Push(chartpath string, force bool) error {
if err != nil {
return fmt.Errorf("Looks like %s is not a valid chart repository or cannot be reached: %v", r.name, err)
}
c, err := chartutil.Load(chartpath)
c, err := loader.Load(chartpath)
if err != nil {
return fmt.Errorf("Error loading chart: %v", err)
}
Expand Down Expand Up @@ -223,11 +222,9 @@ func (r Repo) uploadChart(chartpath string) error {

func getRepoUrl(repoName string) (string, error) {

repositoryConfigPath := envOr("HELM_REPOSITORY_CONFIG", helmpath.ConfigPath("repositories.yaml"))
var repoUrl string
repositoryConfigPath := envOr("HELM_HOME", environment.DefaultHelmHome)
helmconfig := helmpath.Home(repositoryConfigPath)

f, err := helmrepo.LoadRepositoriesFile(helmconfig.RepositoryFile())
f, err := helmrepo.LoadFile(repositoryConfigPath)
if err != nil {
return repoUrl, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "blob"
version: "0.2.0"
version: "0.3.0"
usage: "(Helm v3) Manage chart repositories on Blob Storage(Azure Blob, GCS, S3)"
description: |-
(Helm v3) Manage chart repositories on Blob Storage(Azure Blob, GCS, S3).
Expand Down
Binary file removed testdata/helmV3/mychart-0.1.0.tgz
Binary file not shown.

0 comments on commit 80e2094

Please sign in to comment.