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

fix: package publish progress bar frozen at zero #2367

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/pkg/oci/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
type OrasRemote struct {
repo *remote.Repository
root *Manifest
Transport *helpers.Transport
progTransport *helpers.Transport
targetPlatform *ocispec.Platform
log *slog.Logger
}
Expand All @@ -46,7 +46,7 @@ func WithPlainHTTP(plainHTTP bool) Modifier {
// WithInsecureSkipVerify sets the insecure TLS flag for the remote
func WithInsecureSkipVerify(insecure bool) Modifier {
return func(o *OrasRemote) {
o.Transport.Base.(*http.Transport).TLSClientConfig.InsecureSkipVerify = insecure
o.progTransport.Base.(*http.Transport).TLSClientConfig.InsecureSkipVerify = insecure
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func NewOrasRemote(url string, platform ocispec.Platform, mods ...Modifier) (*Or
client.Client.Transport = transport
o := &OrasRemote{
repo: &remote.Repository{Client: client},
Transport: helpers.NewTransport(transport, nil),
progTransport: helpers.NewTransport(transport, nil),
targetPlatform: &platform,
log: slog.Default(),
}
Expand All @@ -101,6 +101,18 @@ func NewOrasRemote(url string, platform ocispec.Platform, mods ...Modifier) (*Or
return o, nil
}

// SetProgressWriter sets the progress writer for the remote
func (o *OrasRemote) SetProgressWriter(bar helpers.ProgressWriter) {
o.progTransport.ProgressBar = bar
o.repo.Client.(*auth.Client).Client.Transport = o.progTransport
}

// ClearProgressWriter clears the progress writer for the remote
func (o *OrasRemote) ClearProgressWriter() {
o.progTransport.ProgressBar = nil
o.repo.Client.(*auth.Client).Client.Transport = o.progTransport
}

// Repo gives you access to the underlying remote repository
func (o *OrasRemote) Repo() *remote.Repository {
return o.repo
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/zoci/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (r *Remote) PublishPackage(ctx context.Context, pkg *types.ZarfPackage, pat

progressBar := message.NewProgressBar(total, fmt.Sprintf("Publishing %s:%s", r.Repo().Reference.Repository, r.Repo().Reference.Reference))
defer progressBar.Stop()
r.Transport.ProgressBar = progressBar
r.SetProgressWriter(progressBar)
defer r.ClearProgressWriter()

publishedDesc, err := oras.Copy(ctx, src, root.Digest.String(), r.Repo(), "", copyOpts)
if err != nil {
Expand Down