client.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. package types // import "github.com/docker/docker/api/types"
  2. import (
  3. "bufio"
  4. "io"
  5. "net"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/filters"
  8. units "github.com/docker/go-units"
  9. )
  10. // CheckpointCreateOptions holds parameters to create a checkpoint from a container
  11. type CheckpointCreateOptions struct {
  12. CheckpointID string
  13. CheckpointDir string
  14. Exit bool
  15. }
  16. // CheckpointListOptions holds parameters to list checkpoints for a container
  17. type CheckpointListOptions struct {
  18. CheckpointDir string
  19. }
  20. // CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
  21. type CheckpointDeleteOptions struct {
  22. CheckpointID string
  23. CheckpointDir string
  24. }
  25. // ContainerAttachOptions holds parameters to attach to a container.
  26. type ContainerAttachOptions struct {
  27. Stream bool
  28. Stdin bool
  29. Stdout bool
  30. Stderr bool
  31. DetachKeys string
  32. Logs bool
  33. }
  34. // ContainerCommitOptions holds parameters to commit changes into a container.
  35. type ContainerCommitOptions struct {
  36. Reference string
  37. Comment string
  38. Author string
  39. Changes []string
  40. Pause bool
  41. Config *container.Config
  42. }
  43. // ContainerExecInspect holds information returned by exec inspect.
  44. type ContainerExecInspect struct {
  45. ExecID string `json:"ID"`
  46. ContainerID string
  47. Running bool
  48. ExitCode int
  49. Pid int
  50. }
  51. // ContainerListOptions holds parameters to list containers with.
  52. type ContainerListOptions struct {
  53. Size bool
  54. All bool
  55. Latest bool
  56. Since string
  57. Before string
  58. Limit int
  59. Filters filters.Args
  60. }
  61. // ContainerLogsOptions holds parameters to filter logs with.
  62. type ContainerLogsOptions struct {
  63. ShowStdout bool
  64. ShowStderr bool
  65. Since string
  66. Until string
  67. Timestamps bool
  68. Follow bool
  69. Tail string
  70. Details bool
  71. }
  72. // ContainerRemoveOptions holds parameters to remove containers.
  73. type ContainerRemoveOptions struct {
  74. RemoveVolumes bool
  75. RemoveLinks bool
  76. Force bool
  77. }
  78. // ContainerStartOptions holds parameters to start containers.
  79. type ContainerStartOptions struct {
  80. CheckpointID string
  81. CheckpointDir string
  82. }
  83. // CopyToContainerOptions holds information
  84. // about files to copy into a container
  85. type CopyToContainerOptions struct {
  86. AllowOverwriteDirWithFile bool
  87. CopyUIDGID bool
  88. }
  89. // EventsOptions holds parameters to filter events with.
  90. type EventsOptions struct {
  91. Since string
  92. Until string
  93. Filters filters.Args
  94. }
  95. // NetworkListOptions holds parameters to filter the list of networks with.
  96. type NetworkListOptions struct {
  97. Filters filters.Args
  98. }
  99. // HijackedResponse holds connection information for a hijacked request.
  100. type HijackedResponse struct {
  101. Conn net.Conn
  102. Reader *bufio.Reader
  103. }
  104. // Close closes the hijacked connection and reader.
  105. func (h *HijackedResponse) Close() {
  106. h.Conn.Close()
  107. }
  108. // CloseWriter is an interface that implements structs
  109. // that close input streams to prevent from writing.
  110. type CloseWriter interface {
  111. CloseWrite() error
  112. }
  113. // CloseWrite closes a readWriter for writing.
  114. func (h *HijackedResponse) CloseWrite() error {
  115. if conn, ok := h.Conn.(CloseWriter); ok {
  116. return conn.CloseWrite()
  117. }
  118. return nil
  119. }
  120. // ImageBuildOptions holds the information
  121. // necessary to build images.
  122. type ImageBuildOptions struct {
  123. Tags []string
  124. SuppressOutput bool
  125. RemoteContext string
  126. NoCache bool
  127. Remove bool
  128. ForceRemove bool
  129. PullParent bool
  130. Isolation container.Isolation
  131. CPUSetCPUs string
  132. CPUSetMems string
  133. CPUShares int64
  134. CPUQuota int64
  135. CPUPeriod int64
  136. Memory int64
  137. MemorySwap int64
  138. CgroupParent string
  139. NetworkMode string
  140. ShmSize int64
  141. Dockerfile string
  142. Ulimits []*units.Ulimit
  143. // BuildArgs needs to be a *string instead of just a string so that
  144. // we can tell the difference between "" (empty string) and no value
  145. // at all (nil). See the parsing of buildArgs in
  146. // api/server/router/build/build_routes.go for even more info.
  147. BuildArgs map[string]*string
  148. AuthConfigs map[string]AuthConfig
  149. Context io.Reader
  150. Labels map[string]string
  151. // squash the resulting image's layers to the parent
  152. // preserves the original image and creates a new one from the parent with all
  153. // the changes applied to a single layer
  154. Squash bool
  155. // CacheFrom specifies images that are used for matching cache. Images
  156. // specified here do not need to have a valid parent chain to match cache.
  157. CacheFrom []string
  158. SecurityOpt []string
  159. ExtraHosts []string // List of extra hosts
  160. Target string
  161. SessionID string
  162. Platform string
  163. // Version specifies the version of the unerlying builder to use
  164. Version BuilderVersion
  165. // BuildID is an optional identifier that can be passed together with the
  166. // build request. The same identifier can be used to gracefully cancel the
  167. // build with the cancel request.
  168. BuildID string
  169. // Outputs defines configurations for exporting build results. Only supported
  170. // in BuildKit mode
  171. Outputs []ImageBuildOutput
  172. }
  173. // ImageBuildOutput defines configuration for exporting a build result
  174. type ImageBuildOutput struct {
  175. Type string
  176. Attrs map[string]string
  177. }
  178. // BuilderVersion sets the version of underlying builder to use
  179. type BuilderVersion string
  180. const (
  181. // BuilderV1 is the first generation builder in docker daemon
  182. BuilderV1 BuilderVersion = "1"
  183. // BuilderBuildKit is builder based on moby/buildkit project
  184. BuilderBuildKit BuilderVersion = "2"
  185. )
  186. // ImageBuildResponse holds information
  187. // returned by a server after building
  188. // an image.
  189. type ImageBuildResponse struct {
  190. Body io.ReadCloser
  191. OSType string
  192. }
  193. // ImageCreateOptions holds information to create images.
  194. type ImageCreateOptions struct {
  195. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
  196. Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
  197. }
  198. // ImageImportSource holds source information for ImageImport
  199. type ImageImportSource struct {
  200. Source io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
  201. SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
  202. }
  203. // ImageImportOptions holds information to import images from the client host.
  204. type ImageImportOptions struct {
  205. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  206. Message string // Message is the message to tag the image with
  207. Changes []string // Changes are the raw changes to apply to this image
  208. Platform string // Platform is the target platform of the image
  209. }
  210. // ImageListOptions holds parameters to list images with.
  211. type ImageListOptions struct {
  212. // All controls whether all images in the graph are filtered, or just
  213. // the heads.
  214. All bool
  215. // Filters is a JSON-encoded set of filter arguments.
  216. Filters filters.Args
  217. // SharedSize indicates whether the shared size of images should be computed.
  218. SharedSize bool
  219. // ContainerCount indicates whether container count should be computed.
  220. ContainerCount bool
  221. }
  222. // ImageLoadResponse returns information to the client about a load process.
  223. type ImageLoadResponse struct {
  224. // Body must be closed to avoid a resource leak
  225. Body io.ReadCloser
  226. JSON bool
  227. }
  228. // ImagePullOptions holds information to pull images.
  229. type ImagePullOptions struct {
  230. All bool
  231. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  232. PrivilegeFunc RequestPrivilegeFunc
  233. Platform string
  234. }
  235. // RequestPrivilegeFunc is a function interface that
  236. // clients can supply to retry operations after
  237. // getting an authorization error.
  238. // This function returns the registry authentication
  239. // header value in base 64 format, or an error
  240. // if the privilege request fails.
  241. type RequestPrivilegeFunc func() (string, error)
  242. // ImagePushOptions holds information to push images.
  243. type ImagePushOptions ImagePullOptions
  244. // ImageRemoveOptions holds parameters to remove images.
  245. type ImageRemoveOptions struct {
  246. Force bool
  247. PruneChildren bool
  248. }
  249. // ImageSearchOptions holds parameters to search images with.
  250. type ImageSearchOptions struct {
  251. RegistryAuth string
  252. PrivilegeFunc RequestPrivilegeFunc
  253. Filters filters.Args
  254. Limit int
  255. }
  256. // ResizeOptions holds parameters to resize a tty.
  257. // It can be used to resize container ttys and
  258. // exec process ttys too.
  259. type ResizeOptions struct {
  260. Height uint
  261. Width uint
  262. }
  263. // NodeListOptions holds parameters to list nodes with.
  264. type NodeListOptions struct {
  265. Filters filters.Args
  266. }
  267. // NodeRemoveOptions holds parameters to remove nodes with.
  268. type NodeRemoveOptions struct {
  269. Force bool
  270. }
  271. // ServiceCreateOptions contains the options to use when creating a service.
  272. type ServiceCreateOptions struct {
  273. // EncodedRegistryAuth is the encoded registry authorization credentials to
  274. // use when updating the service.
  275. //
  276. // This field follows the format of the X-Registry-Auth header.
  277. EncodedRegistryAuth string
  278. // QueryRegistry indicates whether the service update requires
  279. // contacting a registry. A registry may be contacted to retrieve
  280. // the image digest and manifest, which in turn can be used to update
  281. // platform or other information about the service.
  282. QueryRegistry bool
  283. }
  284. // ServiceCreateResponse contains the information returned to a client
  285. // on the creation of a new service.
  286. type ServiceCreateResponse struct {
  287. // ID is the ID of the created service.
  288. ID string
  289. // Warnings is a set of non-fatal warning messages to pass on to the user.
  290. Warnings []string `json:",omitempty"`
  291. }
  292. // Values for RegistryAuthFrom in ServiceUpdateOptions
  293. const (
  294. RegistryAuthFromSpec = "spec"
  295. RegistryAuthFromPreviousSpec = "previous-spec"
  296. )
  297. // ServiceUpdateOptions contains the options to be used for updating services.
  298. type ServiceUpdateOptions struct {
  299. // EncodedRegistryAuth is the encoded registry authorization credentials to
  300. // use when updating the service.
  301. //
  302. // This field follows the format of the X-Registry-Auth header.
  303. EncodedRegistryAuth string
  304. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  305. // into this field. While it does open API users up to racy writes, most
  306. // users may not need that level of consistency in practice.
  307. // RegistryAuthFrom specifies where to find the registry authorization
  308. // credentials if they are not given in EncodedRegistryAuth. Valid
  309. // values are "spec" and "previous-spec".
  310. RegistryAuthFrom string
  311. // Rollback indicates whether a server-side rollback should be
  312. // performed. When this is set, the provided spec will be ignored.
  313. // The valid values are "previous" and "none". An empty value is the
  314. // same as "none".
  315. Rollback string
  316. // QueryRegistry indicates whether the service update requires
  317. // contacting a registry. A registry may be contacted to retrieve
  318. // the image digest and manifest, which in turn can be used to update
  319. // platform or other information about the service.
  320. QueryRegistry bool
  321. }
  322. // ServiceListOptions holds parameters to list services with.
  323. type ServiceListOptions struct {
  324. Filters filters.Args
  325. // Status indicates whether the server should include the service task
  326. // count of running and desired tasks.
  327. Status bool
  328. }
  329. // ServiceInspectOptions holds parameters related to the "service inspect"
  330. // operation.
  331. type ServiceInspectOptions struct {
  332. InsertDefaults bool
  333. }
  334. // TaskListOptions holds parameters to list tasks with.
  335. type TaskListOptions struct {
  336. Filters filters.Args
  337. }
  338. // PluginRemoveOptions holds parameters to remove plugins.
  339. type PluginRemoveOptions struct {
  340. Force bool
  341. }
  342. // PluginEnableOptions holds parameters to enable plugins.
  343. type PluginEnableOptions struct {
  344. Timeout int
  345. }
  346. // PluginDisableOptions holds parameters to disable plugins.
  347. type PluginDisableOptions struct {
  348. Force bool
  349. }
  350. // PluginInstallOptions holds parameters to install a plugin.
  351. type PluginInstallOptions struct {
  352. Disabled bool
  353. AcceptAllPermissions bool
  354. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  355. RemoteRef string // RemoteRef is the plugin name on the registry
  356. PrivilegeFunc RequestPrivilegeFunc
  357. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  358. Args []string
  359. }
  360. // SwarmUnlockKeyResponse contains the response for Engine API:
  361. // GET /swarm/unlockkey
  362. type SwarmUnlockKeyResponse struct {
  363. // UnlockKey is the unlock key in ASCII-armored format.
  364. UnlockKey string
  365. }
  366. // PluginCreateOptions hold all options to plugin create.
  367. type PluginCreateOptions struct {
  368. RepoName string
  369. }