Skip to content

Commit

Permalink
global spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrareddyp committed Apr 25, 2024
1 parent 0286638 commit b9dd3da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
26 changes: 10 additions & 16 deletions pkg/airgapped/plugin_bundle_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ func (o *UploadPluginBundleOptions) UploadPluginBundle() error {
imagesUploaded := 0
// Iterate through all the images and publish them to the remote repository
var repoImagePath string
spinner := component.NewOutputWriterSpinner(component.WithOutputStream(os.Stderr))
defer spinner.StopSpinner()
for _, ic := range manifest.ImagesToCopy {
imageTar := filepath.Join(pluginBundleDir, ic.SourceTarFilePath)
repoImagePath, err = utils.JoinURL(o.DestinationRepo, ic.RelativeImagePath)
if err != nil {
return errors.Wrap(err, "error while constructing the repo image path")
}
if uploadErr := o.uploadImage(imageTar, repoImagePath, totalImages, imagesUploaded); uploadErr != nil {
if uploadErr := o.uploadImage(imageTar, repoImagePath, totalImages, imagesUploaded, spinner); uploadErr != nil {
return uploadErr
}
time.Sleep(3 * time.Second)
imagesUploaded++
}
log.Infof("---------------------------")
Expand Down Expand Up @@ -106,32 +107,25 @@ func (o *UploadPluginBundleOptions) UploadPluginBundle() error {
return nil
}

func (o *UploadPluginBundleOptions) uploadImage(imageTar, repoImagePath string, totalImages, imagesUploaded int) error {
func (o *UploadPluginBundleOptions) uploadImage(imageTar, repoImagePath string, totalImages, imagesUploaded int, spinner component.OutputWriterSpinner) error {
uploadingMsg := fmt.Sprintf("[%d/%d] uploading image %q", totalImages, imagesUploaded, repoImagePath)
errorMsg := fmt.Sprintf("[%d/%d] error while uploading image %q", totalImages, imagesUploaded, repoImagePath)
uploadedMsg := "[%d/%d] uploaded image %q"

var spinner component.OutputWriterSpinner
if component.IsTTYEnabled() {
// Initialize the spinner
spinner = component.NewOutputWriterSpinner(
component.WithOutputStream(os.Stderr),
component.WithSpinnerText(uploadingMsg),
component.WithSpinnerStarted(),
)
if !component.IsTTYEnabled() {
spinner.SetText(uploadingMsg)
spinner.SetFinalText(errorMsg, log.LogTypeERROR)
defer spinner.StopSpinner()
spinner.StartSpinner()
} else {
log.Infof(uploadingMsg, totalImages, imagesUploaded, repoImagePath)
}

if err := o.ImageProcessor.CopyImageFromTar(imageTar, repoImagePath); err != nil {
return errors.Wrapf(err, errorMsg, repoImagePath)
}

time.Sleep(1 * time.Second)
uploadedMsg = fmt.Sprintf(uploadedMsg, totalImages, imagesUploaded+1, repoImagePath)
if spinner != nil {
spinner.SetFinalText(uploadedMsg, log.LogTypeINFO)
if spinner == nil {
spinner.SetFinalText("", "")
} else {
log.Infof(uploadedMsg, totalImages, imagesUploaded, repoImagePath)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (r *registry) CopyImageFromTar(sourceTarFile, destImageRepo string) error {
Insecure: r.opts.Insecure,
}
}

originalStdout := os.Stderr
pr, pw, pipeErr := os.Pipe()
if pipeErr != nil {
Expand Down

0 comments on commit b9dd3da

Please sign in to comment.