github.com/souleb/helm@v3.0.0-beta.3+incompatible/cmd/helm/package.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "io" 22 "io/ioutil" 23 "path/filepath" 24 25 "github.com/pkg/errors" 26 "github.com/spf13/cobra" 27 28 "helm.sh/helm/pkg/action" 29 "helm.sh/helm/pkg/cli/values" 30 "helm.sh/helm/pkg/downloader" 31 "helm.sh/helm/pkg/getter" 32 ) 33 34 const packageDesc = ` 35 This command packages a chart into a versioned chart archive file. If a path 36 is given, this will look at that path for a chart (which must contain a 37 Chart.yaml file) and then package that directory. 38 39 If no path is given, this will look in the present working directory for a 40 Chart.yaml file, and (if found) build the current directory into a chart. 41 42 Versioned chart archives are used by Helm package repositories. 43 ` 44 45 func newPackageCmd(out io.Writer) *cobra.Command { 46 client := action.NewPackage() 47 valueOpts := &values.Options{} 48 49 cmd := &cobra.Command{ 50 Use: "package [CHART_PATH] [...]", 51 Short: "package a chart directory into a chart archive", 52 Long: packageDesc, 53 RunE: func(cmd *cobra.Command, args []string) error { 54 if len(args) == 0 { 55 return errors.Errorf("need at least one argument, the path to the chart") 56 } 57 if client.Sign { 58 if client.Key == "" { 59 return errors.New("--key is required for signing a package") 60 } 61 if client.Keyring == "" { 62 return errors.New("--keyring is required for signing a package") 63 } 64 } 65 client.RepositoryConfig = settings.RepositoryConfig 66 client.RepositoryCache = settings.RepositoryCache 67 p := getter.All(settings) 68 vals, err := valueOpts.MergeValues(p) 69 if err != nil { 70 return err 71 } 72 73 for i := 0; i < len(args); i++ { 74 path, err := filepath.Abs(args[i]) 75 if err != nil { 76 return err 77 } 78 79 if client.DependencyUpdate { 80 downloadManager := &downloader.Manager{ 81 Out: ioutil.Discard, 82 ChartPath: path, 83 Keyring: client.Keyring, 84 Getters: p, 85 Debug: settings.Debug, 86 RepositoryConfig: settings.RepositoryConfig, 87 RepositoryCache: settings.RepositoryCache, 88 } 89 90 if err := downloadManager.Update(); err != nil { 91 return err 92 } 93 } 94 p, err := client.Run(path, vals) 95 if err != nil { 96 return err 97 } 98 fmt.Fprintf(out, "Successfully packaged chart and saved it to: %s\n", p) 99 } 100 return nil 101 }, 102 } 103 104 f := cmd.Flags() 105 f.BoolVar(&client.Sign, "sign", false, "use a PGP private key to sign this package") 106 f.StringVar(&client.Key, "key", "", "name of the key to use when signing. Used if --sign is true") 107 f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "location of a public keyring") 108 f.StringVar(&client.Version, "version", "", "set the version on the chart to this semver version") 109 f.StringVar(&client.AppVersion, "app-version", "", "set the appVersion on the chart to this version") 110 f.StringVarP(&client.Destination, "destination", "d", ".", "location to write the chart.") 111 f.BoolVarP(&client.DependencyUpdate, "dependency-update", "u", false, `update dependencies from "Chart.yaml" to dir "charts/" before packaging`) 112 addValueOptionsFlags(f, valueOpts) 113 114 return cmd 115 }