allow dependency versions to be overwritten on package update

Signed-off-by: Gregory Hill <greg.hill@monax.io>
pull/7312/head
Gregory Hill 6 years ago
parent 1ff8272748
commit 43ad5e9e9e
No known key found for this signature in database
GPG Key ID: 54841B20DB63C22B

@ -88,6 +88,7 @@ func newPackageCmd(out io.Writer) *cobra.Command {
Keyring: client.Keyring,
Getters: p,
Debug: settings.Debug,
DependencyVersions: client.DependencyVersions,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
}
@ -114,6 +115,7 @@ func newPackageCmd(out io.Writer) *cobra.Command {
f.StringVar(&client.AppVersion, "app-version", "", "set the appVersion on the chart to this version")
f.StringVarP(&client.Destination, "destination", "d", ".", "location to write the chart.")
f.BoolVarP(&client.DependencyUpdate, "dependency-update", "u", false, `update dependencies from "Chart.yaml" to dir "charts/" before packaging`)
f.StringToStringVar(&client.DependencyVersions, "set-dependency-version", make(map[string]string), "set dependency versions. Used if --dependency-update is true")
addValueOptionsFlags(f, valueOpts)
return cmd

@ -43,6 +43,7 @@ type Package struct {
AppVersion string
Destination string
DependencyUpdate bool
DependencyVersions map[string]string
RepositoryConfig string
RepositoryCache string
@ -77,6 +78,15 @@ func (p *Package) Run(path string, vals map[string]interface{}) (string, error)
ch.Metadata.AppVersion = p.AppVersion
}
if p.DependencyUpdate {
// only alter these upon successful update
for _, d := range ch.Metadata.Dependencies {
if v, ok := p.DependencyVersions[d.Name]; ok {
d.Version = v
}
}
}
if reqs := ch.Metadata.Dependencies; reqs != nil {
if err := CheckDependencies(ch, reqs); err != nil {
return "", err

@ -57,6 +57,8 @@ type Manager struct {
SkipUpdate bool
// Getter collection for the operation
Getters []getter.Provider
// DependencyVersions allows us to explicitly set versions
DependencyVersions map[string]string
RepositoryConfig string
RepositoryCache string
}
@ -123,6 +125,13 @@ func (m *Manager) Update() error {
return nil
}
// Allow dependency versions to be overwritten.
for _, d := range c.Metadata.Dependencies {
if v, ok := m.DependencyVersions[d.Name]; ok {
d.Version = v
}
}
// Check that all of the repos we're dependent on actually exist and
// the repo index names.
repoNames, err := m.resolveRepoNames(req)

Loading…
Cancel
Save