oci_windows.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package windowsoci
  2. // This file contains the Windows spec for a container. At the time of
  3. // writing, Windows does not have a spec defined in opencontainers/specs,
  4. // hence this is an interim workaround. TODO Windows: FIXME @jhowardmsft
  5. import "fmt"
  6. // WindowsSpec is the full specification for Windows containers.
  7. type WindowsSpec struct {
  8. Spec
  9. // Windows is platform specific configuration for Windows based containers.
  10. Windows Windows `json:"windows"`
  11. }
  12. // Spec is the base configuration for the container. It specifies platform
  13. // independent configuration. This information must be included when the
  14. // bundle is packaged for distribution.
  15. type Spec struct {
  16. // Version is the version of the specification that is supported.
  17. Version string `json:"ociVersion"`
  18. // Platform is the host information for OS and Arch.
  19. Platform Platform `json:"platform"`
  20. // Process is the container's main process.
  21. Process Process `json:"process"`
  22. // Root is the root information for the container's filesystem.
  23. Root Root `json:"root"`
  24. // Hostname is the container's host name.
  25. Hostname string `json:"hostname,omitempty"`
  26. // Mounts profile configuration for adding mounts to the container's filesystem.
  27. Mounts []Mount `json:"mounts"`
  28. }
  29. // Windows contains platform specific configuration for Windows based containers.
  30. type Windows struct {
  31. // Resources contain information for handling resource constraints for the container
  32. Resources *Resources `json:"resources,omitempty"`
  33. // Networking contains the platform specific network settings for the container.
  34. Networking *Networking `json:"networking,omitempty"`
  35. // FirstStart is used for an optimization on first boot of Windows
  36. FirstStart bool `json:"first_start,omitempty"`
  37. // LayerFolder is the path to the current layer folder
  38. LayerFolder string `json:"layer_folder,omitempty"`
  39. // Layer paths of the parent layers
  40. LayerPaths []string `json:"layer_paths,omitempty"`
  41. // HvRuntime contains settings specific to Hyper-V containers, omitted if not using Hyper-V isolation
  42. HvRuntime *HvRuntime `json:"hv_runtime,omitempty"`
  43. }
  44. // Process contains information to start a specific application inside the container.
  45. type Process struct {
  46. // Terminal indicates if stderr should NOT be attached for the container.
  47. Terminal bool `json:"terminal"`
  48. // ConsoleSize contains the initial h,w of the console size
  49. InitialConsoleSize [2]int `json:"-"`
  50. // User specifies user information for the process.
  51. User User `json:"user"`
  52. // Args specifies the binary and arguments for the application to execute.
  53. Args []string `json:"args"`
  54. // Env populates the process environment for the process.
  55. Env []string `json:"env,omitempty"`
  56. // Cwd is the current working directory for the process and must be
  57. // relative to the container's root.
  58. Cwd string `json:"cwd"`
  59. }
  60. // User contains the user information for Windows
  61. type User struct {
  62. User string `json:"user,omitempty"`
  63. }
  64. // Root contains information about the container's root filesystem on the host.
  65. type Root struct {
  66. // Path is the absolute path to the container's root filesystem.
  67. Path string `json:"path"`
  68. // Readonly makes the root filesystem for the container readonly before the process is executed.
  69. Readonly bool `json:"readonly"`
  70. }
  71. // Platform specifies OS and arch information for the host system that the container
  72. // is created for.
  73. type Platform struct {
  74. // OS is the operating system.
  75. OS string `json:"os"`
  76. // Arch is the architecture
  77. Arch string `json:"arch"`
  78. // OSVersion is the version of the operating system.
  79. OSVersion string `json:"os.version,omitempty"`
  80. }
  81. // Mount specifies a mount for a container.
  82. type Mount struct {
  83. // Destination is the path where the mount will be placed relative to the container's root. The path and child directories MUST exist, a runtime MUST NOT create directories automatically to a mount point.
  84. Destination string `json:"destination"`
  85. // Type specifies the mount kind.
  86. Type string `json:"type"`
  87. // Source specifies the source path of the mount. In the case of bind mounts
  88. // this would be the file on the host.
  89. Source string `json:"source"`
  90. // Readonly specifies if the mount should be read-only
  91. Readonly bool `json:"readonly"`
  92. }
  93. // HvRuntime contains settings specific to Hyper-V containers
  94. type HvRuntime struct {
  95. // ImagePath is the path to the Utility VM image for this container
  96. ImagePath string `json:"image_path,omitempty"`
  97. }
  98. // Networking contains the platform specific network settings for the container
  99. type Networking struct {
  100. // List of endpoints to be attached to the container
  101. EndpointList []string `json:"endpoints,omitempty"`
  102. }
  103. // Storage contains storage resource management settings
  104. type Storage struct {
  105. // Specifies maximum Iops for the system drive
  106. Iops *uint64 `json:"iops,omitempty"`
  107. // Specifies maximum bytes per second for the system drive
  108. Bps *uint64 `json:"bps,omitempty"`
  109. // Sandbox size indicates the size to expand the system drive to if it is currently smaller
  110. SandboxSize *uint64 `json:"sandbox_size,omitempty"`
  111. }
  112. // Memory contains memory settings for the container
  113. type Memory struct {
  114. // Memory limit (in bytes).
  115. Limit *int64 `json:"limit,omitempty"`
  116. // Memory reservation (in bytes).
  117. Reservation *uint64 `json:"reservation,omitempty"`
  118. }
  119. // CPU contains information for cpu resource management
  120. type CPU struct {
  121. // Number of CPUs available to the container. This is an appoximation for Windows Server Containers.
  122. Count *uint64 `json:"count,omitempty"`
  123. // CPU shares (relative weight (ratio) vs. other containers with cpu shares). Range is from 1 to 10000.
  124. Shares *uint64 `json:"shares,omitempty"`
  125. // Percent of available CPUs usable by the container.
  126. Percent *int64 `json:"percent,omitempty"`
  127. }
  128. // Network network resource management information
  129. type Network struct {
  130. // Bandwidth is the maximum egress bandwidth in bytes per second
  131. Bandwidth *uint64 `json:"bandwidth,omitempty"`
  132. }
  133. // Resources has container runtime resource constraints
  134. // TODO Windows containerd. This structure needs ratifying with the old resources
  135. // structure used on Windows and the latest OCI spec.
  136. type Resources struct {
  137. // Memory restriction configuration
  138. Memory *Memory `json:"memory,omitempty"`
  139. // CPU resource restriction configuration
  140. CPU *CPU `json:"cpu,omitempty"`
  141. // Storage restriction configuration
  142. Storage *Storage `json:"storage,omitempty"`
  143. // Network restriction configuration
  144. Network *Network `json:"network,omitempty"`
  145. }
  146. const (
  147. // VersionMajor is for an API incompatible changes
  148. VersionMajor = 0
  149. // VersionMinor is for functionality in a backwards-compatible manner
  150. VersionMinor = 3
  151. // VersionPatch is for backwards-compatible bug fixes
  152. VersionPatch = 0
  153. // VersionDev indicates development branch. Releases will be empty string.
  154. VersionDev = ""
  155. )
  156. // Version is the specification version that the package types support.
  157. var Version = fmt.Sprintf("%d.%d.%d%s (Windows)", VersionMajor, VersionMinor, VersionPatch, VersionDev)