Rewrite Chart.yaml dependencies' paths to local file://charts/...chart... to package a fully self-contained tgz package

pull/13525/head
killerwhile 10 months ago committed by Benoit
parent cc0bbbd6d6
commit a2cc1b55a0

@ -91,8 +91,12 @@ func newPackageCmd(out io.Writer) *cobra.Command {
}
if client.DependencyUpdate {
dmOut := io.Discard
if settings.Debug {
dmOut = out
}
downloadManager := &downloader.Manager{
Out: io.Discard,
Out: dmOut,
ChartPath: path,
Keyring: client.Keyring,
Getters: p,
@ -125,6 +129,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.BoolVarP(&client.RewriteChart, "rewrite-chart", "r", false, `rewrite dependencies in "Chart.yaml" to point to local "charts/" folder before packaging`)
f.StringVar(&client.Username, "username", "", "chart repository username where to locate the requested chart")
f.StringVar(&client.Password, "password", "", "chart repository password where to locate the requested chart")
f.StringVar(&client.CertFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")

@ -22,10 +22,13 @@ import (
"os"
"syscall"
"helm.sh/helm/v3/internal/resolver"
"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
"golang.org/x/term"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/provenance"
@ -43,6 +46,7 @@ type Package struct {
AppVersion string
Destination string
DependencyUpdate bool
RewriteChart bool
RepositoryConfig string
RepositoryCache string
@ -85,6 +89,25 @@ func (p *Package) Run(path string, _ map[string]interface{}) (string, error) {
return "", err
}
}
if p.RewriteChart {
if len(ch.Metadata.Dependencies) != 0 {
if ch.Lock == nil {
return "", fmt.Errorf("lock is nil. Please run package -u -r to have Chart.lock set")
}
lockedDependencies := make([]*chart.Dependency, 0, len(ch.Metadata.Dependencies))
for i, d := range ch.Metadata.Dependencies {
d.Repository = "file://charts/" + d.Name
ch.Metadata.Dependencies[i] = d
lockedDependencies = append(lockedDependencies, d)
}
ch.Lock.Dependencies = lockedDependencies
newDigest, err := resolver.HashReq(ch.Metadata.Dependencies, ch.Lock.Dependencies)
if err != nil {
return "", err
}
ch.Lock.Digest = newDigest
}
}
var dest string
if p.Destination == "." {

Loading…
Cancel
Save