image_changes.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package containerd
  2. import (
  3. "context"
  4. "github.com/containerd/containerd/mount"
  5. "github.com/containerd/log"
  6. "github.com/docker/docker/container"
  7. "github.com/docker/docker/pkg/archive"
  8. "github.com/docker/docker/pkg/stringid"
  9. )
  10. func (i *ImageService) Changes(ctx context.Context, container *container.Container) ([]archive.Change, error) {
  11. snapshotter := i.client.SnapshotService(container.Driver)
  12. info, err := snapshotter.Stat(ctx, container.ID)
  13. if err != nil {
  14. return nil, err
  15. }
  16. id := stringid.GenerateRandomID()
  17. parentViewKey := container.ID + "-parent-view-" + id
  18. imageMounts, _ := snapshotter.View(ctx, parentViewKey, info.Parent)
  19. defer func() {
  20. if err := snapshotter.Remove(ctx, parentViewKey); err != nil {
  21. log.G(ctx).WithError(err).Warn("error removing the parent view snapshot")
  22. }
  23. }()
  24. var changes []archive.Change
  25. err = i.PerformWithBaseFS(ctx, container, func(containerRoot string) error {
  26. return mount.WithReadonlyTempMount(ctx, imageMounts, func(imageRoot string) error {
  27. changes, err = archive.ChangesDirs(containerRoot, imageRoot)
  28. return err
  29. })
  30. })
  31. return changes, err
  32. }