Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify a different base url for charts when pushing and reindexing #46

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions cmd/helms3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func main() {
String()
pushForce := pushCmd.Flag("force", "Replace the chart if it already exists. This can cause the repository to lose existing chart; use it with care").
Bool()
repoBaseURL := pushCmd.Flag("base-url", "the base url of the chart packages that are published").
Default("").
String()

reindexCmd := cli.Command(actionReindex, "Reindex the repository.")
reindexTargetRepository := reindexCmd.Arg("repo", "Target repository to reindex").
Expand Down Expand Up @@ -121,17 +124,19 @@ func main() {

case actionPush:
act = pushAction{
chartPath: *pushChartPath,
repoName: *pushTargetRepository,
force: *pushForce,
acl: *acl,
chartPath: *pushChartPath,
repoName: *pushTargetRepository,
force: *pushForce,
acl: *acl,
repoBaseURL: *repoBaseURL,
}

case actionReindex:
fmt.Fprint(os.Stderr, "Warning: reindex feature is in beta. If you experience any issues,\nplease provide your feedback here: https://github.com/hypnoglow/helm-s3/issues/22\n\n")
act = reindexAction{
repoName: *reindexTargetRepository,
acl: *acl,
repoName: *reindexTargetRepository,
acl: *acl,
repoBaseURL: *repoBaseURL,
}
defer fmt.Printf("Repository %s was successfully reindexed.\n", *reindexTargetRepository)

Expand Down
19 changes: 14 additions & 5 deletions cmd/helms3/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ var (
)

type pushAction struct {
chartPath string
repoName string
force bool
acl string
chartPath string
repoName string
force bool
acl string
repoBaseURL string
}

func (act pushAction) Run(ctx context.Context) error {
Expand Down Expand Up @@ -114,7 +115,15 @@ func (act pushAction) Run(ctx context.Context) error {
return errors.WithMessage(err, "load index from downloaded file")
}

if err := idx.AddOrReplace(chart.GetMetadata(), fname, repoEntry.URL, hash); err != nil {
// if you have a public repository, you might want to set chart base url to the s3 buckets website address
var repoBaseURL string
if act.repoBaseURL == "" {
repoBaseURL = repoEntry.URL
} else {
repoBaseURL = act.repoBaseURL
}

if err := idx.AddOrReplace(chart.GetMetadata(), fname, repoBaseURL, hash); err != nil {
return errors.WithMessage(err, "add/replace chart in the index")
}
idx.SortEntries()
Expand Down
15 changes: 12 additions & 3 deletions cmd/helms3/reindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

type reindexAction struct {
repoName string
acl string
repoName string
acl string
repoBaseURL string
}

func (act reindexAction) Run(ctx context.Context) error {
Expand All @@ -30,11 +31,19 @@ func (act reindexAction) Run(ctx context.Context) error {

items, errs := storage.Traverse(ctx, repoEntry.URL)

// if you have a public repository, you might want to set chart base url to the s3 buckets website address
var repoBaseURL string
if act.repoBaseURL == "" {
repoBaseURL = repoEntry.URL
} else {
repoBaseURL = act.repoBaseURL
}

builtIndex := make(chan *index.Index, 1)
go func() {
idx := index.New()
for item := range items {
idx.Add(item.Meta, item.Filename, repoEntry.URL, item.Hash)
idx.Add(item.Meta, item.Filename, repoBaseURL, item.Hash)
}
idx.SortEntries()

Expand Down