Recursive dependency build added

Loop prevention added with wired threshold.
Docs updated.
reviewable/pr2278/r1
Gergo Huszty 9 years ago
parent 5af676cda1
commit 33fbcda4cc

@ -42,6 +42,7 @@ type dependencyBuildCmd struct {
verify bool verify bool
keyring string keyring string
helmhome helmpath.Home helmhome helmpath.Home
recursive bool
} }
func newDependencyBuildCmd(out io.Writer) *cobra.Command { func newDependencyBuildCmd(out io.Writer) *cobra.Command {
@ -67,6 +68,7 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.BoolVar(&dbc.verify, "verify", false, "verify the packages against signatures") f.BoolVar(&dbc.verify, "verify", false, "verify the packages against signatures")
f.StringVar(&dbc.keyring, "keyring", defaultKeyring(), "keyring containing public keys") f.StringVar(&dbc.keyring, "keyring", defaultKeyring(), "keyring containing public keys")
f.BoolVar(&dbc.recursive, "recursive", false, "recursive mode")
return cmd return cmd
} }
@ -78,10 +80,13 @@ func (d *dependencyBuildCmd) run() error {
HelmHome: d.helmhome, HelmHome: d.helmhome,
Keyring: d.keyring, Keyring: d.keyring,
Getters: defaultgetters.Get(settings), Getters: defaultgetters.Get(settings),
Recursive: d.recursive,
Debug: settings.FlagDebug,
} }
if d.verify { if d.verify {
man.Verify = downloader.VerifyIfPossible man.Verify = downloader.VerifyIfPossible
} }
return man.Build() _, err := man.Build()
return err
} }

@ -24,6 +24,7 @@ helm dependency build [flags] CHART
``` ```
--keyring string keyring containing public keys (default "~/.gnupg/pubring.gpg") --keyring string keyring containing public keys (default "~/.gnupg/pubring.gpg")
--recursive recursive mode
--verify verify the packages against signatures --verify verify the packages against signatures
``` ```

@ -32,6 +32,10 @@ of 'helm dependency update'.
\fB\-\-keyring\fP="~/.gnupg/pubring.gpg" \fB\-\-keyring\fP="~/.gnupg/pubring.gpg"
keyring containing public keys keyring containing public keys
.PP
\fB\-\-recursive\fP[=false]
recursive mode
.PP .PP
\fB\-\-verify\fP[=false] \fB\-\-verify\fP[=false]
verify the packages against signatures verify the packages against signatures

@ -57,6 +57,8 @@ type Manager struct {
SkipUpdate bool SkipUpdate bool
// Getter collection for the operation // Getter collection for the operation
Getters []getter.Prop Getters []getter.Prop
// Recursive mode collects the dependencies to the lowest level
Recursive bool
} }
// Build rebuilds a local charts directory from a lockfile. // Build rebuilds a local charts directory from a lockfile.
@ -64,46 +66,66 @@ type Manager struct {
// If the lockfile is not present, this will run a Manager.Update() // If the lockfile is not present, this will run a Manager.Update()
// //
// If SkipUpdate is set, this will not update the repository. // If SkipUpdate is set, this will not update the repository.
func (m *Manager) Build() error { func (m *Manager) Build() (int, error) {
c, err := m.loadChartDir() c, err := m.loadChartDir()
if err != nil { if err != nil {
return err return 0, err
} }
// If a lock file is found, run a build from that. Otherwise, just do // If a lock file is found, run a build from that. Otherwise, just do
// an update. // an update.
lock, err := chartutil.LoadRequirementsLock(c) lock, err := chartutil.LoadRequirementsLock(c)
if err != nil { if err != nil {
return m.Update() return 0, m.Update()
} }
// A lock must accompany a requirements.yaml file. // A lock must accompany a requirements.yaml file.
req, err := chartutil.LoadRequirements(c) reqs, err := chartutil.LoadRequirements(c)
if err != nil { if err != nil {
return fmt.Errorf("requirements.yaml cannot be opened: %s", err) return 0, fmt.Errorf("requirements.yaml cannot be opened: %s", err)
} }
if sum, err := resolver.HashReq(req); err != nil || sum != lock.Digest { if sum, err := resolver.HashReq(reqs); err != nil || sum != lock.Digest {
return fmt.Errorf("requirements.lock is out of sync with requirements.yaml") return 0, fmt.Errorf("requirements.lock is out of sync with requirements.yaml")
} }
// Check that all of the repos we're dependent on actually exist. // Check that all of the repos we're dependent on actually exist.
if err := m.hasAllRepos(lock.Dependencies); err != nil { if err := m.hasAllRepos(lock.Dependencies); err != nil {
return err return 0, err
} }
if !m.SkipUpdate { if !m.SkipUpdate {
// For each repo in the file, update the cached copy of that repo // For each repo in the file, update the cached copy of that repo
if err := m.UpdateRepositories(); err != nil { if err := m.UpdateRepositories(); err != nil {
return err return 0, err
} }
} }
// Now we need to fetch every package here into charts/ // Now we need to fetch every package here into charts/
if err := m.downloadAll(lock.Dependencies); err != nil { if err := m.downloadAll(lock.Dependencies); err != nil {
return err return 0, err
} }
return nil myDeps := len(reqs.Dependencies)
if m.Recursive {
depM := *m
for _, dep := range reqs.Dependencies {
depM.ChartPath = filepath.Join(m.ChartPath, "charts", dep.Name)
depM.SkipUpdate = true
fmt.Fprintln(m.Out, "Getting requirements recursively for:", depM.ChartPath)
depOfDeps, err := depM.Build()
if err != nil {
return 0, err
}
myDeps += depOfDeps
if myDeps > 100 {
return 0, fmt.Errorf("Loop prevention kicked in.")
}
}
}
if m.Debug {
fmt.Fprintln(m.Out, "Done with", m.ChartPath, ", deps:", myDeps)
}
return myDeps, nil
} }
// Update updates a local charts directory. // Update updates a local charts directory.
@ -246,6 +268,13 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error {
if _, _, err := dl.DownloadTo(churl, "", destPath); err != nil { if _, _, err := dl.DownloadTo(churl, "", destPath); err != nil {
return fmt.Errorf("could not download %s: %s", churl, err) return fmt.Errorf("could not download %s: %s", churl, err)
} }
if m.Recursive == true {
tarPath := filepath.Join(destPath, filepath.Base(churl))
fmt.Fprintln(m.Out, "Unpacking:", tarPath)
if err = chartutil.ExpandFile(destPath, tarPath); err != nil {
return fmt.Errorf("Error while unpacking: %s", err)
}
}
} }
return nil return nil
} }

@ -323,6 +323,8 @@ _helm_dependency_build()
flags+=("--keyring=") flags+=("--keyring=")
local_nonpersistent_flags+=("--keyring=") local_nonpersistent_flags+=("--keyring=")
flags+=("--recursive")
local_nonpersistent_flags+=("--recursive")
flags+=("--verify") flags+=("--verify")
local_nonpersistent_flags+=("--verify") local_nonpersistent_flags+=("--verify")
flags+=("--debug") flags+=("--debug")

Loading…
Cancel
Save