Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

fix(docker): getting an image by ID or a name with tag #425

Merged
merged 4 commits into from
Mar 17, 2022

Conversation

afdesk
Copy link
Collaborator

@afdesk afdesk commented Mar 17, 2022

fanal tries to find an image by name (with tag).
If it's not found, fanal will look for an image by ID.

Fixes a problem from #405

Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

Please refer to the original PR.

imageID = ref.String() // Image ID uses "<Image_ID>" pattern
inspect, _, err = c.ImageInspectWithRaw(context.Background(), imageID)
if err != nil {
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", ref.Name(), err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ref.String() returns an original value. I think ref.String() is better here.

Suggested change
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", ref.Name(), err)
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", imageID, err)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -24,10 +24,14 @@ func DockerImage(ref name.Reference) (Image, func(), error) {
}
}()

imageID := ref.String()
imageID := ref.Name() // Image ID uses "<Image_name>:<Tag>" pattern
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
imageID := ref.Name() // Image ID uses "<Image_name>:<Tag>" pattern
// <image_name>:<tag> pattern like "alpine:3.15"
// or
// <image_name>@<digest> pattern like "alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300"
imageID := ref.Name()

Copy link
Collaborator Author

@afdesk afdesk Mar 17, 2022

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

You missed my suggested change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean digest

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry, done

inspect, _, err := c.ImageInspectWithRaw(context.Background(), imageID)
if err != nil {
return nil, cleanup, xerrors.Errorf("unable to inspect the image (%s): %w", imageID, err)
imageID = ref.String() // Image ID uses "<Image_ID>" pattern
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
imageID = ref.String() // Image ID uses "<Image_ID>" pattern
imageID = ref.String() // <image_id> pattern like `5ac716b05a9c`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@knqyf263 knqyf263 merged commit c4fac2e into main Mar 17, 2022
@knqyf263 knqyf263 deleted the fix_docker_name branch March 17, 2022 18:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants