oci_windows.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // Spec is the base configuration for the container.
  7. type Spec struct {
  8. // Version of the Open Container Runtime Specification with which the bundle complies.
  9. Version string `json:"ociVersion"`
  10. // Platform specifies the configuration's target platform.
  11. Platform Platform `json:"platform"`
  12. // Process configures the container process.
  13. Process Process `json:"process"`
  14. // Root configures the container's root filesystem.
  15. Root Root `json:"root"`
  16. // Hostname configures the container's hostname.
  17. Hostname string `json:"hostname,omitempty"`
  18. // Mounts configures additional mounts (on top of Root).
  19. Mounts []Mount `json:"mounts,omitempty"`
  20. // Hooks configures callbacks for container lifecycle events.
  21. Hooks Hooks `json:"hooks"`
  22. // Annotations contains arbitrary metadata for the container.
  23. Annotations map[string]string `json:"annotations,omitempty"`
  24. // Linux is platform specific configuration for Linux based containers.
  25. Linux *Linux `json:"linux,omitempty" platform:"linux"`
  26. // Solaris is platform specific configuration for Solaris containers.
  27. Solaris *Solaris `json:"solaris,omitempty" platform:"solaris"`
  28. // Windows is platform specific configuration for Windows based containers, including Hyper-V containers.
  29. Windows *Windows `json:"windows,omitempty" platform:"windows"`
  30. }
  31. // Windows contains platform specific configuration for Windows based containers.
  32. type Windows struct {
  33. // Resources contains information for handling resource constraints for the container
  34. Resources *WindowsResources `json:"resources,omitempty"`
  35. }
  36. // Process contains information to start a specific application inside the container.
  37. type Process struct {
  38. // Terminal creates an interactive terminal for the container.
  39. Terminal bool `json:"terminal,omitempty"`
  40. // User specifies user information for the process.
  41. User User `json:"user"`
  42. // Args specifies the binary and arguments for the application to execute.
  43. Args []string `json:"args"`
  44. // Env populates the process environment for the process.
  45. Env []string `json:"env,omitempty"`
  46. // Cwd is the current working directory for the process and must be
  47. // relative to the container's root.
  48. Cwd string `json:"cwd"`
  49. // Capabilities are Linux capabilities that are kept for the container.
  50. Capabilities []string `json:"capabilities,omitempty" platform:"linux"`
  51. // Rlimits specifies rlimit options to apply to the process.
  52. Rlimits []Rlimit `json:"rlimits,omitempty" platform:"linux"`
  53. // NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
  54. NoNewPrivileges bool `json:"noNewPrivileges,omitempty" platform:"linux"`
  55. // ApparmorProfile specifies the apparmor profile for the container.
  56. ApparmorProfile string `json:"apparmorProfile,omitempty" platform:"linux"`
  57. // SelinuxLabel specifies the selinux context that the container process is run as.
  58. SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
  59. // ConsoleSize contains the initial size of the console.
  60. ConsoleSize Box `json:"consoleSize" platform:"windows"`
  61. }
  62. // Box specifies height and width dimensions. Used for sizing of a console.
  63. type Box struct {
  64. Height uint
  65. Width uint
  66. }
  67. // User specifies specific user (and group) information for the container process.
  68. type User struct {
  69. // UID is the user id.
  70. UID uint32 `json:"uid" platform:"linux,solaris"`
  71. // GID is the group id.
  72. GID uint32 `json:"gid" platform:"linux,solaris"`
  73. // AdditionalGids are additional group ids set for the container's process.
  74. AdditionalGids []uint32 `json:"additionalGids,omitempty" platform:"linux,solaris"`
  75. // Username is the user name.
  76. Username string `json:"username,omitempty" platform:"windows"`
  77. }
  78. // Root contains information about the container's root filesystem on the host.
  79. type Root struct {
  80. // Path is the absolute path to the container's root filesystem.
  81. Path string `json:"path"`
  82. // Readonly makes the root filesystem for the container readonly before the process is executed.
  83. Readonly bool `json:"readonly"`
  84. }
  85. // Platform specifies OS and arch information for the host system that the container
  86. // is created for.
  87. type Platform struct {
  88. // OS is the operating system.
  89. OS string `json:"os"`
  90. // Arch is the architecture
  91. Arch string `json:"arch"`
  92. }
  93. // Mount specifies a mount for a container.
  94. type Mount struct {
  95. // 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.
  96. Destination string `json:"destination"`
  97. // Type specifies the mount kind.
  98. Type string `json:"type"`
  99. // Source specifies the source path of the mount. In the case of bind mounts on
  100. // Linux based systems this would be the file on the host.
  101. Source string `json:"source"`
  102. // Options are fstab style mount options.
  103. Options []string `json:"options,omitempty"`
  104. }
  105. // WindowsStorage contains storage resource management settings
  106. type WindowsStorage struct {
  107. // Specifies maximum Iops for the system drive
  108. Iops *uint64 `json:"iops,omitempty"`
  109. // Specifies maximum bytes per second for the system drive
  110. Bps *uint64 `json:"bps,omitempty"`
  111. // Sandbox size indicates the size to expand the system drive to if it is currently smaller
  112. SandboxSize *uint64 `json:"sandbox_size,omitempty"`
  113. }
  114. // WindowsMemory contains memory settings for the container
  115. type WindowsMemory struct {
  116. // Memory limit (in bytes).
  117. Limit *int64 `json:"limit,omitempty"`
  118. // Memory reservation (in bytes).
  119. Reservation *uint64 `json:"reservation,omitempty"`
  120. }
  121. // WindowsCPU contains information for cpu resource management
  122. type WindowsCPU struct {
  123. // Number of CPUs available to the container. This is an appoximation for Windows Server Containers.
  124. Count *uint64 `json:"count,omitempty"`
  125. // CPU shares (relative weight (ratio) vs. other containers with cpu shares). Range is from 1 to 10000.
  126. Shares *uint64 `json:"shares,omitempty"`
  127. // Percent of available CPUs usable by the container.
  128. Percent *int64 `json:"percent,omitempty"`
  129. }
  130. // WindowsNetwork contains network resource management information
  131. type WindowsNetwork struct {
  132. // Bandwidth is the maximum egress bandwidth in bytes per second
  133. Bandwidth *uint64 `json:"bandwidth,omitempty"`
  134. }
  135. // WindowsResources has container runtime resource constraints
  136. // TODO Windows containerd. This structure needs ratifying with the old resources
  137. // structure used on Windows and the latest OCI spec.
  138. type WindowsResources struct {
  139. // Memory restriction configuration
  140. Memory *WindowsMemory `json:"memory,omitempty"`
  141. // CPU resource restriction configuration
  142. CPU *WindowsCPU `json:"cpu,omitempty"`
  143. // Storage restriction configuration
  144. Storage *WindowsStorage `json:"storage,omitempty"`
  145. // Network restriction configuration
  146. Network *WindowsNetwork `json:"network,omitempty"`
  147. }
  148. const (
  149. // VersionMajor is for an API incompatible changes
  150. VersionMajor = 0
  151. // VersionMinor is for functionality in a backwards-compatible manner
  152. VersionMinor = 3
  153. // VersionPatch is for backwards-compatible bug fixes
  154. VersionPatch = 0
  155. // VersionDev indicates development branch. Releases will be empty string.
  156. VersionDev = ""
  157. )
  158. // Version is the specification version that the package types support.
  159. var Version = fmt.Sprintf("%d.%d.%d%s (Windows)", VersionMajor, VersionMinor, VersionPatch, VersionDev)
  160. //
  161. // Temporary structures. Ultimately this whole file will be removed.
  162. //
  163. // Linux contains platform specific configuration for Linux based containers.
  164. type Linux struct {
  165. }
  166. // Solaris contains platform specific configuration for Solaris application containers.
  167. type Solaris struct {
  168. }
  169. // Hooks for container setup and teardown
  170. type Hooks struct {
  171. }
  172. // Rlimit type and restrictions. Placeholder only to support the Process structure.
  173. // Not used on Windows, only present for compilation purposes.
  174. type Rlimit struct {
  175. }