github.com/openpitrix/helm@v3.0.0-beta.3+incompatible/cmd/helm/dependency_build.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package main
    17  
    18  import (
    19  	"io"
    20  	"os"
    21  	"path/filepath"
    22  
    23  	"github.com/spf13/cobra"
    24  	"k8s.io/client-go/util/homedir"
    25  
    26  	"helm.sh/helm/cmd/helm/require"
    27  	"helm.sh/helm/pkg/action"
    28  	"helm.sh/helm/pkg/downloader"
    29  	"helm.sh/helm/pkg/getter"
    30  )
    31  
    32  const dependencyBuildDesc = `
    33  Build out the charts/ directory from the Chart.lock file.
    34  
    35  Build is used to reconstruct a chart's dependencies to the state specified in
    36  the lock file. This will not re-negotiate dependencies, as 'helm dependency update'
    37  does.
    38  
    39  If no lock file is found, 'helm dependency build' will mirror the behavior
    40  of 'helm dependency update'.
    41  `
    42  
    43  func newDependencyBuildCmd(out io.Writer) *cobra.Command {
    44  	client := action.NewDependency()
    45  
    46  	cmd := &cobra.Command{
    47  		Use:   "build CHART",
    48  		Short: "rebuild the charts/ directory based on the Chart.lock file",
    49  		Long:  dependencyBuildDesc,
    50  		Args:  require.MaximumNArgs(1),
    51  		RunE: func(cmd *cobra.Command, args []string) error {
    52  			chartpath := "."
    53  			if len(args) > 0 {
    54  				chartpath = filepath.Clean(args[0])
    55  			}
    56  			man := &downloader.Manager{
    57  				Out:              out,
    58  				ChartPath:        chartpath,
    59  				Keyring:          client.Keyring,
    60  				Getters:          getter.All(settings),
    61  				RepositoryConfig: settings.RepositoryConfig,
    62  				RepositoryCache:  settings.RepositoryCache,
    63  				Debug:            settings.Debug,
    64  			}
    65  			if client.Verify {
    66  				man.Verify = downloader.VerifyIfPossible
    67  			}
    68  			return man.Build()
    69  		},
    70  	}
    71  
    72  	f := cmd.Flags()
    73  	f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures")
    74  	f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys")
    75  
    76  	return cmd
    77  }
    78  
    79  // defaultKeyring returns the expanded path to the default keyring.
    80  func defaultKeyring() string {
    81  	if v, ok := os.LookupEnv("GNUPGHOME"); ok {
    82  		return filepath.Join(v, "pubring.gpg")
    83  	}
    84  	return filepath.Join(homedir.HomeDir(), ".gnupg", "pubring.gpg")
    85  }