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

Image inspect rework #3017

Merged
merged 1 commit into from
Jun 2, 2024
Merged

Image inspect rework #3017

merged 1 commit into from
Jun 2, 2024

Conversation

apostasie
Copy link
Contributor

@apostasie apostasie commented May 17, 2024

Apologies for the big commit here, but I do not believe we can fix image inspect incrementally, as some of the core assumptions are wrong (specifically in the way we walk images, in the returned data types, etc).

Furthermore, there is more work needed here.
Other command which are doing images lookup (rmi) are also faulty.
Fixing these as well would turn this PR into a large monster, and I would rather do that separately as a follow-up once this one is reviewed and accepted.

So, this PR fixes the following:

Obviously, the reworked image inspect should be wired into inspect at a later point, and the overall revised lookup mechanics should be generalized and used by other methods (like rmi) - again, as a follow-up.
Overall the current ImageWalker should either be removed or replaced with the updated workflow here.

Please note that our implementation also diverges from Docker, for good reasons:
For example, when retrieving an image using a digest and a tagged name, we do verify the tag name against the result, unlike Moby which only verifies the image name (because of their use of ParseDockerRef, which should be banned from existence IMHO…).
Because of that, Moby will allow inspecting images using random bogus tag names as long as the digest matches and return a different image than the requested one altogether.
This has had far reaching consequences: specifically, mind-bending bugs for build caching invalidation.
I do believe Moby must fix it, but it’s not my problem.

What is left overall:

Also, this PR adds a bunch of integration tests on the above.

PTAL

cc @AkihiroSuda

i := &Image{}

imgoci := n.ImageConfig
func ImageFromNative(nativeImage *native.Image) (*Image, error) {
Copy link
Contributor Author

@apostasie apostasie May 17, 2024

Choose a reason for hiding this comment

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

Light cleanup:

  • improve variable name readability
  • introduce Variant, Parent and VirtualSize
  • populate RepoDigest

// Deprecated: TODO: ContainerConfig *container.Config
}

// From: https://github.com/moby/moby/blob/v26.1.2/api/types/graph_driver_data.go
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Provisional for future implementation

@@ -47,28 +47,39 @@ import (
"github.com/tidwall/gjson"
)

// Image mimics a `docker image inspect` object.
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L340-L374
// From https://github.com/moby/moby/blob/v26.1.2/api/types/types.go#L34-L140
type Image struct {
Copy link
Contributor Author

@apostasie apostasie May 17, 2024

Choose a reason for hiding this comment

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

Updated with latest definition and reordered a bit for readability.

  • moved down deprecated fields
  • added VirtualSize, Parent, Variant

@@ -37,7 +37,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/runtime/restart"
gocni "github.com/containerd/go-cni"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unnecessary.

README.md Outdated
@@ -268,6 +268,10 @@ docker build -t test-integration --target test-integration .
docker run -t --rm --privileged test-integration
```

To run a single integration test (in this case, `image_inspect_test`):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a note for newcomers.

// test RawFormat support
base.Cmd("image", "inspect", testutil.CommonImage, "--format", "{{.Id}}").AssertOK()

// test typedFormat support
base.Cmd("image", "inspect", testutil.CommonImage, "--format", "{{.ID}}").AssertOK()
}

func inspectImageHelper(base *testutil.Base, identifier ...string) []dockercompat.Image {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cannot use the one in testutil, as it assumes single entry array.

@apostasie apostasie force-pushed the dev-image-inspect branch 2 times, most recently from 3dbeff3 to 27becf0 Compare May 17, 2024 00:35
}

func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
testutil.DockerIncompatible(t)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If really necessary, I could split this in two parts - the part that is docker compatible and the part that is not.

Either way we need first to resolve #3011

@AkihiroSuda AkihiroSuda requested a review from Zheaoli May 17, 2024 00:40
@apostasie
Copy link
Contributor Author

Reviewer:

I don't want to introduce churn here by regularly adding more fixes.
The PR in its current state may have some minor issues (specifically there is one: Docker Hub names are not shortened properly before being added to RepoTags).
In the name of keeping our sanity, and if these minor issues are not a big deal for you, I will fix these in a follow-up once this is merged.

@apostasie
Copy link
Contributor Author

apostasie commented May 17, 2024

Windows CI failure is on me.
Will try to fix it.
I need help with that Windows thing.
I do not have access to a Windows system, and not quite sure how to use it properly so we can test with linux images.

@apostasie
Copy link
Contributor Author

Note this is likely fixing issues like #2061

@Zheaoli
Copy link
Member

Zheaoli commented May 18, 2024

I will convert this PR to a draft before we solve the Windows issue together. I will help to figure out what happened.

@Zheaoli Zheaoli marked this pull request as draft May 18, 2024 18:11
@Zheaoli
Copy link
Member

Zheaoli commented May 18, 2024

https://github.com/containerd/nerdctl/blob/main/cmd/nerdctl/image_save_test.go#L35C22-L35C44

You can output the inspect.RepoDigests[0] in test during the debug, I think there one more : char in the string

@apostasie
Copy link
Contributor Author

apostasie commented May 18, 2024

https://github.com/containerd/nerdctl/blob/main/cmd/nerdctl/image_save_test.go#L35C22-L35C44

You can output the inspect.RepoDigests[0] in test during the debug, I think there one more : char in the string

Thanks @Zheaoli

I believe the failure on save_test (TestSaveById) are unrelated, and are just flakyness.

The actual test failing is the one I introduced, and the issue here is that I am using test images that do not have a Windows version, so, pull fails on windows: https://github.com/containerd/nerdctl/actions/runs/9133230483/job/25136088395?pr=3017#step:8:569

As I said, unfortunately, I know very little about Win...

@apostasie
Copy link
Contributor Author

More accurately, the issue is:
time="2024-05-18T17:41:26Z" level=fatal msg="failed to extract layer sha256:d4fc045c9e3a848011de66f34b81f052d4f2c15a17bb196d637e526349601820: hcsshim::ProcessBaseLayer \\\\?\\C:\\ProgramData\\containerd\\root\\io.containerd.snapshotter.v1.windows\\snapshots\\106: The system cannot find the path specified.: unknown"

And I know nothing about hcsshim, or why it would fail extracting an image.

@apostasie apostasie marked this pull request as ready for review May 30, 2024 02:32
@apostasie
Copy link
Contributor Author

@Zheaoli @AkihiroSuda
CI is green.
I disabled the test on window for now.
Will revisit soon when I get a Windows environment to test on.

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone May 30, 2024
@AkihiroSuda AkihiroSuda requested a review from ktock May 30, 2024 02:34
README.md Outdated Show resolved Hide resolved
cmd/nerdctl/image_inspect_test.go Show resolved Hide resolved
cmd/nerdctl/image_inspect_test.go Outdated Show resolved Hide resolved
Comment on lines +162 to +161
// Prove that invalid reference return no result without crashing
for _, id := range []string{"∞∞∞∞∞∞∞∞∞∞", "busybox:∞∞∞∞∞∞∞∞∞∞"} {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use more readable string like ! or a very long tag?

FYI: https://docs.docker.com/reference/cli/docker/image/tag/#description

The tag must be valid ASCII and can contain lowercase and uppercase letters, digits, underscores, periods, and hyphens. It can't start with a period or hyphen and must be no longer than 128 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer something outside of the ASCII range if you don't mind, as this tends to uncover issues not necessarily seen without.

Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

LGTM on green

Signed-off-by: apostasie <[email protected]>
Copy link
Member

@Zheaoli Zheaoli left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda
Copy link
Member

@ktock @Zheaoli You can merge PRs

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