Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 15:49:16 -05:00
pkg-proxy/internal/mirror/helm.go
Simon Chrzanowski 17e4fc763f Mirror Helm charts
Mirroring pkg:helm PURLs failed with an unsupported ecosystem error. The
namespace now names the upstream.helm repository, as the Helm handler
caches charts per repository: pkg:helm/{repository}/{chart}@{version}.

The chart is found in the repository's index through the handler's own
index lookup, fetched from the first URL the release lists, as helm does,
checked against the listed digest and cached under the repository,
digest and filename the handler serves it from. The index goes through
the metadata cache, so helm finds the chart there while the repository is
down. Unversioned PURLs list every version in the index.

Charts without a repository, from an unconfigured one, or listed in an
OCI registry are refused; the last are pulled through /v2, and the error
names the pkg:oci PURL that mirrors them.
2026-10-25 19:37:22 +01:00

40 lines
1.2 KiB
Go

package mirror
import (
"context"
"errors"
"strings"
"github.com/git-pkgs/proxy/internal/handler"
)
// ChartMirrorer caches Helm charts from the configured repositories the way
// the Helm handler serves them.
type ChartMirrorer interface {
MirrorChart(ctx context.Context, repository, chart, version string) (*handler.CacheResult, error)
}
var (
errHelmNoRepository = errors.New("helm charts need the upstream.helm repository as the namespace, such as pkg:helm/{repository}/{chart}@{version}")
errHelmUnavailable = errors.New("mirroring Helm charts isn't available here")
)
// mirrorHelm mirrors a chart release. The PURL namespace names the
// upstream.helm repository, since the handler caches charts per repository.
func (m *Mirror) mirrorHelm(ctx context.Context, pv PackageVersion, tracker *progressTracker) {
repository, chart, ok := strings.Cut(pv.Name, "/")
if !ok || repository == "" || chart == "" {
m.recordFailure(tracker, pv, errHelmNoRepository)
return
}
if m.Charts == nil {
m.recordFailure(tracker, pv, errHelmUnavailable)
return
}
result, err := m.Charts.MirrorChart(ctx, repository, chart, pv.Version)
if err != nil {
m.recordFailure(tracker, pv, err)
return
}
m.recordResult(tracker, pv, result)
}