Skip to content

Conversation

abhisek
Copy link
Member

@abhisek abhisek commented May 29, 2025

No description provided.

@abhisek abhisek requested review from Copilot and KunalSin9h May 29, 2025 14:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR performs miscellaneous cleanup and refactoring for the container image resolution logic.

  • Updated the CLI flag description for image pulling behavior.
  • Refactored and simplified the container image resolution workflows, reorganizing imports and error handling.
  • Renamed imageStr to imageRef, switched config to a value type, and updated tests to use the new isLocalFile flag.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
scan.go Updated the description of the --image-no-remote flag
pkg/readers/container_image_resolve_workflow.go Reorganized imports and rewrote image resolution workflows
pkg/readers/container_image_reader.go Renamed fields, switched config to a value type, and improved errors
pkg/readers/container_image_reader_test.go Adjusted tests to assert isLocalFile instead of using checkPathExists
Comments suppressed due to low confidence (3)

pkg/readers/container_image_resolve_workflow.go:194

  • The loop in getScalibrImage returns on the first non-unsupported error or non-nil image, preventing later workflows from running. Instead, only return on a valid image or an irrecoverable error, and continue on imageResolverUnsupportedError.
workflow := []imageResolutionWorkflowFunc{

pkg/readers/container_image_reader_test.go:77

  • [nitpick] The test name TestCheckPathExists no longer matches its behavior (it now asserts isLocalFile). Consider renaming it to reflect that it's testing local-file detection.
func TestCheckPathExists(t *testing.T) {

pkg/readers/container_image_resolve_workflow.go:20

  • imageFromLocalDockerImageCatalog contains significant logic branches (skipping local files, listing images, saving, temp files). Consider adding dedicated unit tests to cover success, unsupported, and error paths.
func (c containerImageReader) imageFromLocalDockerImageCatalog(ctx context.Context) (*scalibrlayerimage.Image, error) {

// create tem directory in /tmp for storing `POSIX tar archive` in file
tempTarFile, err := os.CreateTemp(os.TempDir(), "image-data-*.tar")

image, err := c.imageFromLocalTarFile(ctx)
Copy link
Preview

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling imageFromLocalTarFile here ignores the temporary tar file just created; it will load the original imageRef instead of the saved tarball. Replace with scalibrlayerimage.FromTarball(tempTarFile.Name(), ...) or adjust the helper to accept a file path.

Suggested change
image, err := c.imageFromLocalTarFile(ctx)
image, err := scalibrlayerimage.FromTarball(tempTarFile.Name(), scalibrlayerimage.DefaultConfig())

Copilot uses AI. Check for mistakes.

@abhisek abhisek merged commit 2d988f1 into feat/local-image May 29, 2025
2 checks passed
@abhisek abhisek deleted the feat/container-image-scanning-local-image-support branch May 29, 2025 16:54
abhisek added a commit that referenced this pull request May 29, 2025
* refactor: convert current image resolution into workflow pattern

* feat: image from local tarball folder

* feat: image from local docker catalog

* refacot: decompose docker image catalog resolver into multiple functions

* refactor: using utilit function for logging and return error

* feat: remove tem tar dir after image obj is created

* refactor: handle empty nil error in log and error funciton

* removed local image not supported test

* fix: error fmt.Errorf with non-constant values

* go mod tidy

* fix: linter unreachable  code

* refactor: removed unwanted parameter

* test: added scenerio for different image scan operations

* fix: added scenario into all.sh

* fix: missed .sh extension for one entry

* fix: test bad file path for local tar scan

* remvoed logger and error combined function

* refactor: using context form top of tree

* feat: using custom error for image resolution unsupported

* refactor: returning unsupported workflow error for each docker api fail

* feat: added no-remote flag for disable remote fetch

* feat: --image-no-remote

* fix: test, creating temp files witn \/ causing issue

* chore: Misc cleanup for Container Image Resolver (#499)

* chore: Misc cleanup

* fix: Bug with docker image resolver

* fix: Error msg

* chore: Improve debug logging for docker enumeration

* chore: Improve debug logging for docker enumeration

---------

Co-authored-by: Abhisek Datta <abhisek.datta@gmail.com>
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.

2 participants