Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating helm packages without needing the helm binary #72

Merged
merged 4 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Available Commands:
help Help about any command
index Update Helm repo index.yaml for the given GitHub repo
upload Upload Helm chart packages to GitHub Releases
package Package Helm charts
version Print version information

Flags:
Expand Down
84 changes: 84 additions & 0 deletions cr/cmd/package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright The Helm Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"os"
"path/filepath"

"github.com/helm/chart-releaser/pkg/config"
"github.com/spf13/cobra"
"github.com/ulule/deepcopier"
"helm.sh/helm/v3/pkg/action"
)

// packageCmd represents the package command
var packageCmd = &cobra.Command{
Use: "package [/path/to/chart1] [/path/to/chart/2]",
Short: "Package Helm charts",
Long: `Package Helm charts ready for release.
If you wish to use advanced packaging
options such as creating signed packages or
updating chart dependencies please use
"helm package" instead.`,
RunE: func(cmd *cobra.Command, args []string) error {
var settings map[string]interface{}
var err error

config, err := config.LoadConfiguration(cfgFile, cmd, getRequiredPackageArgs())
if err != nil {
return err
}
client := action.NewPackage()
// valueOpts := &values.Options{}
paulczar marked this conversation as resolved.
Show resolved Hide resolved

if config.PackagePath == "" {
paulczar marked this conversation as resolved.
Show resolved Hide resolved
config.PackagePath = "."
}
client.Destination = config.PackagePath
charts := args
if len(charts) == 0 {
charts[0] = "."
paulczar marked this conversation as resolved.
Show resolved Hide resolved
}
for i := 0; i < len(charts); i++ {
path, err := filepath.Abs(charts[i])
if err != nil {
return err
}
if _, err := os.Stat(args[0]); err != nil {
return err
}
deepcopier.Copy(config).To(settings)
packageRun, err := client.Run(path, settings)

if err != nil {
return err
}

fmt.Printf("Successfully packaged chart in %s and saved it to: %s\n", path, packageRun)
}
return nil
},
}

func getRequiredPackageArgs() []string {
return []string{"package-path"}
}

func init() {
rootCmd.AddCommand(packageCmd)
packageCmd.Flags().StringP("package-path", "p", ".cr-release-packages", "Path to directory with chart packages")
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2 // indirect
github.com/Azure/go-autorest/autorest/to v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Songmu/retry v0.1.0
github.com/google/go-github/v30 v30.0.0
github.com/goreleaser/goreleaser v0.129.0
github.com/helm/helm v2.16.9+incompatible
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.11.0 // indirect
github.com/onsi/gomega v1.8.1 // indirect
Expand All @@ -18,9 +20,11 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.5.1
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/tools v0.0.0-20200204192400-7124308813f3
helm.sh/helm/v3 v3.1.2
k8s.io/helm v2.16.9+incompatible // indirect
)

exclude (
Expand Down
Loading