Skip to content

feat: print x/y progress to the stdout #4545

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

Merged
Changes from 1 commit
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
81 changes: 42 additions & 39 deletions pkg/image/airgap.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ func PushImagesFromTempRegistry(airgapRootDir string, imageList []string, option
defer wc.Close()
}

totalImages := len(imageInfos)
var imageCounter int
for imageID, imageInfo := range imageInfos {
srcRef, err := tempRegistry.SrcRef(imageID)
if err != nil {
Expand Down Expand Up @@ -280,6 +282,8 @@ func PushImagesFromTempRegistry(airgapRootDir string, imageList []string, option
ReportWriter: reportWriter,
},
}
imageCounter++
fmt.Printf("Pushing image %d/%d\n", imageCounter, totalImages)
if err := pushImage(pushImageOpts); err != nil {
return errors.Wrapf(err, "failed to push image %s", imageID)
}
Expand Down Expand Up @@ -699,6 +703,8 @@ func PushEmbeddedClusterArtifacts(airgapBundle string, opts imagetypes.PushEmbed
}
defer gzipReader.Close()

var artifacts []string

tarReader := tar.NewReader(gzipReader)
pushedArtifacts := make([]string, 0)
for {
Expand All @@ -718,52 +724,49 @@ func PushEmbeddedClusterArtifacts(airgapBundle string, opts imagetypes.PushEmbed
continue
}

if err := func() error {
dstFilePath := filepath.Join(tmpDir, header.Name)
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
return errors.Wrap(err, "failed to create path")
}
defer os.RemoveAll(dstFilePath)
dstFilePath := filepath.Join(tmpDir, header.Name)
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
return nil, errors.Wrap(err, "failed to create path")
}

dstFile, err := os.Create(dstFilePath)
if err != nil {
return errors.Wrap(err, "failed to create file")
}
defer dstFile.Close()
dstFile, err := os.Create(dstFilePath)
if err != nil {
return nil, errors.Wrap(err, "failed to create file")
}

if _, err := io.Copy(dstFile, tarReader); err != nil {
return errors.Wrap(err, "failed to copy file data")
}
if _, err := io.Copy(dstFile, tarReader); err != nil {
dstFile.Close()
return nil, errors.Wrap(err, "failed to copy file data")
}

// push each file as an oci artifact to the registry
name := filepath.Base(dstFilePath)
repository := filepath.Join("embedded-cluster", imageutil.SanitizeRepo(name))
artifactFile := imagetypes.OCIArtifactFile{
Name: name,
Path: dstFilePath,
MediaType: EmbeddedClusterMediaType,
}
dstFile.Close()
artifacts = append(artifacts, dstFilePath)
}

pushOCIArtifactOpts := imagetypes.PushOCIArtifactOptions{
Files: []imagetypes.OCIArtifactFile{artifactFile},
ArtifactType: EmbeddedClusterArtifactType,
Registry: opts.Registry,
Repository: repository,
Tag: opts.Tag,
HTTPClient: opts.HTTPClient,
}
for i, dstFilePath := range artifacts {
name := filepath.Base(dstFilePath)
repository := filepath.Join("embedded-cluster", imageutil.SanitizeRepo(name))
artifactFile := imagetypes.OCIArtifactFile{
Name: name,
Path: dstFilePath,
MediaType: EmbeddedClusterMediaType,
}

artifact := fmt.Sprintf("%s:%s", filepath.Join(opts.Registry.Endpoint, opts.Registry.Namespace, repository), opts.Tag)
fmt.Printf("Pushing artifact %s\n", artifact)
if err := pushOCIArtifact(pushOCIArtifactOpts); err != nil {
return errors.Wrapf(err, "failed to push oci artifact %s", name)
}
pushedArtifacts = append(pushedArtifacts, artifact)
pushOCIArtifactOpts := imagetypes.PushOCIArtifactOptions{
Files: []imagetypes.OCIArtifactFile{artifactFile},
ArtifactType: EmbeddedClusterArtifactType,
Registry: opts.Registry,
Repository: repository,
Tag: opts.Tag,
HTTPClient: opts.HTTPClient,
}

return nil
}(); err != nil {
return nil, err
fmt.Printf("Pushing embedded cluster artifact %d/%d\n", i+1, len(artifacts))
artifact := fmt.Sprintf("%s:%s", filepath.Join(opts.Registry.Endpoint, opts.Registry.Namespace, repository), opts.Tag)
if err := pushOCIArtifact(pushOCIArtifactOpts); err != nil {
return nil, errors.Wrapf(err, "failed to push oci artifact %s", name)
}
pushedArtifacts = append(pushedArtifacts, artifact)
}

return pushedArtifacts, nil
Expand Down
Loading