image_changes.go 1.0 KB

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