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

Add diff command #2626

Merged
merged 8 commits into from Nov 6, 2023
Merged

Add diff command #2626

merged 8 commits into from Nov 6, 2023

Conversation

minuk-dev
Copy link
Contributor

@minuk-dev minuk-dev commented Nov 4, 2023

#1376

  • Add diff command:

    • Use continuity/fs to compare filesystem.
  • I referred to

    // NOTE: Moby uses provided rootfs to run container. It doesn't support
    // to commit container created by moby.
    baseImgWithoutPlatform, err := client.ImageService().Get(ctx, info.Image)
    if err != nil {
    return emptyDigest, fmt.Errorf("container %q lacks image (wasn't created by nerdctl?): %w", id, err)
    }
    platformLabel := info.Labels[labels.Platform]
    if platformLabel == "" {
    platformLabel = platforms.DefaultString()
    log.G(ctx).Warnf("Image lacks label %q, assuming the platform to be %q", labels.Platform, platformLabel)
    }
    ocispecPlatform, err := platforms.Parse(platformLabel)
    if err != nil {
    return emptyDigest, err
    }
    log.G(ctx).Debugf("ocispecPlatform=%q", platforms.Format(ocispecPlatform))
    platformMC := platforms.Only(ocispecPlatform)
    baseImg := containerd.NewImageWithPlatform(client, baseImgWithoutPlatform, platformMC)
    baseImgConfig, _, err := imgutil.ReadImageConfig(ctx, baseImg)
    if err != nil {
    return emptyDigest, err
    }
    :

    • But, I don't have any idea to test it. If you have it, please let me know. 🙇
  • (Updated) I found the test of diff command only works on linux, so remove its test from windows. I think I don't use a platform specific feature, but the test output is weird.:

    • Q. Can I make an issue for windows and try in another pr? I'm not sure I can make it.

Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
@minuk-dev minuk-dev marked this pull request as draft November 4, 2023 13:33
@minuk-dev minuk-dev changed the title Add diff command [WIP] Add diff command Nov 4, 2023
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
@minuk-dev minuk-dev changed the title [WIP] Add diff command Add diff command Nov 4, 2023
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
@minuk-dev minuk-dev marked this pull request as ready for review November 4, 2023 14:12
var changes []fs.Change
err = mount.WithReadonlyTempMount(ctx, parent, func(lower string) error {
return mount.WithReadonlyTempMount(ctx, mounts, func(upper string) error {
fs.Changes(ctx, lower, upper, func(ck fs.ChangeKind, s string, fi os.FileInfo, err error) error {
Copy link
Member

Choose a reason for hiding this comment

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

The return value from fs.Changes shouldn’t be ignored

Copy link
Contributor Author

@minuk-dev minuk-dev Nov 4, 2023

Choose a reason for hiding this comment

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

Fixed at 00c0d3b
Thanks a lot. 🙇

}

func diffShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// show container names (TODO: only show containers with logs)
Copy link
Member

Choose a reason for hiding this comment

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

TODO seems wrong

Copy link
Contributor Author

@minuk-dev minuk-dev Nov 4, 2023

Choose a reason for hiding this comment

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

Fixed at d03a599 🙇‍♂️

case fs.ChangeKindModify:
fmt.Fprintln(cmd.OutOrStdout(), "C", change.Path)
case fs.ChangeKindDelete:
fmt.Fprintln(cmd.OutOrStdout(), "D", change.Path)
Copy link
Member

Choose a reason for hiding this comment

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

OutOrStdout should be called only once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed at 3d1a5f1
Thanks a lot really. 👍

@@ -251,6 +251,7 @@ Config file ($NERDCTL_TOML): %s
newPortCommand(),
newStopCommand(),
newStartCommand(),
newDiffCommand(),
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added at a78b50e

Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
@AkihiroSuda AkihiroSuda added this to the v1.7.1 (tentative) milestone Nov 6, 2023
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit ce2f63d into containerd:main Nov 6, 2023
22 checks passed
@AkihiroSuda
Copy link
Member

Next time please squash commits

@minuk-dev minuk-dev deleted the iss1376/diff branch November 14, 2023 13:38
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.

None yet

2 participants