diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 260821db1..5b96f6ece 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -138,6 +138,19 @@ func newRootCmd(out io.Writer) *cobra.Command { // Find and add plugins loadPlugins(cmd, helmpath.Home(homePath()), out) + // Load helmignore file, BuildIgnoreFiles will find helm client location + // for global ignore file, but it needs a current folder location to check + // for local helmignore file. + // ignoreFiles := BuildIgnoreFiles(func() string { + BuildIgnoreFiles(func() string { + // Need to figure out how to get working path + topdir, err := filepath.Abs("./") + if err == nil { + topdir += string(filepath.Separator) + } + return topdir + }()) + return cmd } diff --git a/cmd/helm/package.go b/cmd/helm/package.go index d88fcf214..adb4e7b29 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -31,6 +31,7 @@ import ( "k8s.io/helm/cmd/helm/helmpath" "k8s.io/helm/pkg/chartutil" + "k8s.io/helm/pkg/ignore" "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/provenance" "k8s.io/helm/pkg/repo" @@ -198,3 +199,28 @@ func promptUser(name string) ([]byte, error) { fmt.Println() return pw, err } + +// BuildIgnoreFiles loads global helmignore file if it exists and +// helmignore file from the current folder into a slice of strings. +func BuildIgnoreFiles(dir string) []string { + ignoreFiles := []string{} + + topdir, err := filepath.Abs(dir) + if err == nil { + topdir += string(filepath.Separator) + + f, err := os.Open(topdir + ignore.HelmIgnore) + if err == nil { + defer f.Close() + ignoreFiles = append(ignoreFiles, topdir+ignore.HelmIgnore) + } + } + homeDir := fmt.Sprintf("%s", helmpath.Home(homePath())) + f, err := os.Open(homeDir + ignore.HelmIgnore) + if err == nil { + defer f.Close() + ignoreFiles = append(ignoreFiles, topdir+ignore.HelmIgnore) + } + + return ignoreFiles +} diff --git a/pkg/chartutil/load.go b/pkg/chartutil/load.go index b3dde3c31..2e700f41a 100644 --- a/pkg/chartutil/load.go +++ b/pkg/chartutil/load.go @@ -215,10 +215,25 @@ func LoadFile(name string) (*chart.Chart, error) { return LoadArchive(raw) } +// LoadIgnoreFiles loads helmignore files and returns a reader. +func LoadIgnoreFiles(ignoreFiles []string) *bytes.Reader { + buff := bytes.NewBuffer(nil) + + for _, ignf := range ignoreFiles { + f, err := os.Open(ignf) + if err == nil { + defer f.Close() + io.Copy(buff, f) + } + } + + return bytes.NewReader(buff.Bytes()) +} + // LoadDir loads from a directory. // // This loads charts only from directories. -func LoadDir(dir string) (*chart.Chart, error) { +func LoadDir(dir string, ignoreFiles ...string) (*chart.Chart, error) { topdir, err := filepath.Abs(dir) if err != nil { return nil, err @@ -228,13 +243,12 @@ func LoadDir(dir string) (*chart.Chart, error) { c := &chart.Chart{} rules := ignore.Empty() - ifile := filepath.Join(topdir, ignore.HelmIgnore) - if _, err := os.Stat(ifile); err == nil { - r, err := ignore.ParseFile(ifile) + r := LoadIgnoreFiles(ignoreFiles) + if r.Len() > 0 { + rules, err = ignore.Parse(r) if err != nil { return c, err } - rules = r } rules.AddDefaults()