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

feat(image): add progress bar for image layer pulling #8186

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Dec 26, 2024

Description

TODO:

  • add tests
  • progress bar only works with max-image-size
  • use the progress bar pool to fix flickering when pulling layers in parallel

Example:

❯ ./trivy image redis:5.0 --max-image-size 200mb
2024-12-26T23:47:36+06:00       INFO    [vuln] Vulnerability scanning is enabled
2024-12-26T23:47:36+06:00       INFO    [secret] Secret scanning is enabled
2024-12-26T23:47:36+06:00       INFO    [secret] If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-12-26T23:47:36+06:00       INFO    [secret] Please see also https://aquasecurity.github.io/trivy/dev/docs/scanner/secret#recommendation for faster secret detection
95dff52c35dd 1.35 MiB / 1.35 MiB [-------------------------------------------------------------------------------] 100.00%
c37fdfa5080c 572 B / 572 B [-------------------------------------------------------------------------------------] 100.00%
3716059b2ea5 134 B / 134 B [-------------------------------------------------------------------------------------] 100.00%
84566964bca1 1.69 KiB / 1.69 KiB [-------------------------------------------------------------------------------] 100.00%
598399fdc4dd 6.94 MiB / 6.94 MiB [-------------------------------------------------------------------------------] 100.00%
ec4a38999118 29.96 MiB / 29.96 MiB [-----------------------------------------------------------------------------] 100.00%

Related issues

Related PRs

Remove this section if you don't have related PRs.

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@knqyf263
Copy link
Collaborator

This approach may help.

// progressLayer wraps a v1.Layer to add progress bar functionality
type progressLayer struct {
	v1.Layer
}

func (l *progressLayer) Compressed() (io.ReadCloser, error) {
	rc, err := l.Layer.Compressed()
	if err != nil {
		return nil, err
	}

	size, err := l.Layer.Size()
	if err != nil {
		return nil, err
	}

	bar := pb.Full.Start64(size)
	bar.Set(pb.Bytes, true)

	return bar.NewProxyReader(rc), nil
}

func NewProgressLayer(layer v1.Layer) (v1.Layer, error) {
	return partial.CompressedToLayer(&progressLayer{ Layer: layer})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show progress when fetching layers
2 participants