rootfs_windows.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // +build windows
  2. package image
  3. import (
  4. "crypto/sha512"
  5. "fmt"
  6. "github.com/docker/distribution/digest"
  7. "github.com/docker/docker/layer"
  8. )
  9. // TypeLayersWithBase is used for RootFS.Type for Windows filesystems that have layers and a centrally-stored base layer.
  10. const TypeLayersWithBase = "layers+base"
  11. // RootFS describes images root filesystem
  12. // This is currently a placeholder that only supports layers. In the future
  13. // this can be made into an interface that supports different implementations.
  14. type RootFS struct {
  15. Type string `json:"type"`
  16. DiffIDs []layer.DiffID `json:"diff_ids,omitempty"`
  17. BaseLayer string `json:"base_layer,omitempty"`
  18. }
  19. // BaseLayerID returns the 64 byte hex ID for the baselayer name.
  20. func (r *RootFS) BaseLayerID() string {
  21. if r.Type != TypeLayersWithBase {
  22. panic("tried to get base layer ID without a base layer")
  23. }
  24. baseID := sha512.Sum384([]byte(r.BaseLayer))
  25. return fmt.Sprintf("%x", baseID[:32])
  26. }
  27. // ChainID returns the ChainID for the top layer in RootFS.
  28. func (r *RootFS) ChainID() layer.ChainID {
  29. ids := r.DiffIDs
  30. if r.Type == TypeLayersWithBase {
  31. // Add an extra ID for the base.
  32. baseDiffID := layer.DiffID(digest.FromBytes([]byte(r.BaseLayerID())))
  33. ids = append([]layer.DiffID{baseDiffID}, ids...)
  34. }
  35. return layer.CreateChainID(ids)
  36. }
  37. // NewRootFSWithBaseLayer returns a RootFS struct with a base layer
  38. func NewRootFSWithBaseLayer(baseLayer string) *RootFS {
  39. return &RootFS{Type: TypeLayersWithBase, BaseLayer: baseLayer}
  40. }