rootfs.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package image // import "github.com/docker/docker/image"
  2. import (
  3. "context"
  4. "runtime"
  5. "github.com/containerd/log"
  6. "github.com/docker/docker/layer"
  7. )
  8. // TypeLayers is used for RootFS.Type for filesystems organized into layers.
  9. const TypeLayers = "layers"
  10. // typeLayersWithBase is an older format used by Windows up to v1.12. We
  11. // explicitly handle this as an error case to ensure that a daemon which still
  12. // has an older image like this on disk can still start, even though the
  13. // image itself is not usable. See https://github.com/docker/docker/pull/25806.
  14. const typeLayersWithBase = "layers+base"
  15. // RootFS describes images root filesystem
  16. // This is currently a placeholder that only supports layers. In the future
  17. // this can be made into an interface that supports different implementations.
  18. type RootFS struct {
  19. Type string `json:"type"`
  20. DiffIDs []layer.DiffID `json:"diff_ids,omitempty"`
  21. }
  22. // NewRootFS returns empty RootFS struct
  23. func NewRootFS() *RootFS {
  24. return &RootFS{Type: TypeLayers}
  25. }
  26. // Append appends a new diffID to rootfs
  27. func (r *RootFS) Append(id layer.DiffID) {
  28. r.DiffIDs = append(r.DiffIDs, id)
  29. }
  30. // Clone returns a copy of the RootFS
  31. func (r *RootFS) Clone() *RootFS {
  32. newRoot := NewRootFS()
  33. newRoot.Type = r.Type
  34. newRoot.DiffIDs = make([]layer.DiffID, len(r.DiffIDs))
  35. copy(newRoot.DiffIDs, r.DiffIDs)
  36. return newRoot
  37. }
  38. // ChainID returns the ChainID for the top layer in RootFS.
  39. func (r *RootFS) ChainID() layer.ChainID {
  40. if runtime.GOOS == "windows" && r.Type == typeLayersWithBase {
  41. log.G(context.TODO()).Warnf("Layer type is unsupported on this platform. DiffIDs: '%v'", r.DiffIDs)
  42. return ""
  43. }
  44. return layer.CreateChainID(r.DiffIDs)
  45. }