client.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. // NewHijackedResponse intializes a HijackedResponse type
  100. func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
  101. return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}
  102. }
  103. // HijackedResponse holds connection information for a hijacked request.
  104. type HijackedResponse struct {
  105. mediaType string
  106. Conn net.Conn
  107. Reader *bufio.Reader
  108. }
  109. // Close closes the hijacked connection and reader.
  110. func (h *HijackedResponse) Close() {
  111. h.Conn.Close()
  112. }
  113. // MediaType let client know if HijackedResponse hold a raw or multiplexed stream.
  114. // returns false if HTTP Content-Type is not relevant, and container must be inspected
  115. func (h *HijackedResponse) MediaType() (string, bool) {
  116. if h.mediaType == "" {
  117. return "", false
  118. }
  119. return h.mediaType, true
  120. }
  121. // CloseWriter is an interface that implements structs
  122. // that close input streams to prevent from writing.
  123. type CloseWriter interface {
  124. CloseWrite() error
  125. }
  126. // CloseWrite closes a readWriter for writing.
  127. func (h *HijackedResponse) CloseWrite() error {
  128. if conn, ok := h.Conn.(CloseWriter); ok {
  129. return conn.CloseWrite()
  130. }
  131. return nil
  132. }
  133. // ImageBuildOptions holds the information
  134. // necessary to build images.
  135. type ImageBuildOptions struct {
  136. Tags []string
  137. SuppressOutput bool
  138. RemoteContext string
  139. NoCache bool
  140. Remove bool
  141. ForceRemove bool
  142. PullParent bool
  143. Isolation container.Isolation
  144. CPUSetCPUs string
  145. CPUSetMems string
  146. CPUShares int64
  147. CPUQuota int64
  148. CPUPeriod int64
  149. Memory int64
  150. MemorySwap int64
  151. CgroupParent string
  152. NetworkMode string
  153. ShmSize int64
  154. Dockerfile string
  155. Ulimits []*units.Ulimit
  156. // BuildArgs needs to be a *string instead of just a string so that
  157. // we can tell the difference between "" (empty string) and no value
  158. // at all (nil). See the parsing of buildArgs in
  159. // api/server/router/build/build_routes.go for even more info.
  160. BuildArgs map[string]*string
  161. AuthConfigs map[string]AuthConfig
  162. Context io.Reader
  163. Labels map[string]string
  164. // squash the resulting image's layers to the parent
  165. // preserves the original image and creates a new one from the parent with all
  166. // the changes applied to a single layer
  167. Squash bool
  168. // CacheFrom specifies images that are used for matching cache. Images
  169. // specified here do not need to have a valid parent chain to match cache.
  170. CacheFrom []string
  171. SecurityOpt []string
  172. ExtraHosts []string // List of extra hosts
  173. Target string
  174. SessionID string
  175. Platform string
  176. // Version specifies the version of the unerlying builder to use
  177. Version BuilderVersion
  178. // BuildID is an optional identifier that can be passed together with the
  179. // build request. The same identifier can be used to gracefully cancel the
  180. // build with the cancel request.
  181. BuildID string
  182. // Outputs defines configurations for exporting build results. Only supported
  183. // in BuildKit mode
  184. Outputs []ImageBuildOutput
  185. }
  186. // ImageBuildOutput defines configuration for exporting a build result
  187. type ImageBuildOutput struct {
  188. Type string
  189. Attrs map[string]string
  190. }
  191. // BuilderVersion sets the version of underlying builder to use
  192. type BuilderVersion string
  193. const (
  194. // BuilderV1 is the first generation builder in docker daemon
  195. BuilderV1 BuilderVersion = "1"
  196. // BuilderBuildKit is builder based on moby/buildkit project
  197. BuilderBuildKit BuilderVersion = "2"
  198. )
  199. // ImageBuildResponse holds information
  200. // returned by a server after building
  201. // an image.
  202. type ImageBuildResponse struct {
  203. Body io.ReadCloser
  204. OSType string
  205. }
  206. // ImageCreateOptions holds information to create images.
  207. type ImageCreateOptions struct {
  208. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
  209. Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
  210. }
  211. // ImageImportSource holds source information for ImageImport
  212. type ImageImportSource struct {
  213. 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.
  214. SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
  215. }
  216. // ImageImportOptions holds information to import images from the client host.
  217. type ImageImportOptions struct {
  218. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  219. Message string // Message is the message to tag the image with
  220. Changes []string // Changes are the raw changes to apply to this image
  221. Platform string // Platform is the target platform of the image
  222. }
  223. // ImageListOptions holds parameters to list images with.
  224. type ImageListOptions struct {
  225. // All controls whether all images in the graph are filtered, or just
  226. // the heads.
  227. All bool
  228. // Filters is a JSON-encoded set of filter arguments.
  229. Filters filters.Args
  230. // SharedSize indicates whether the shared size of images should be computed.
  231. SharedSize bool
  232. // ContainerCount indicates whether container count should be computed.
  233. ContainerCount bool
  234. }
  235. // ImageLoadResponse returns information to the client about a load process.
  236. type ImageLoadResponse struct {
  237. // Body must be closed to avoid a resource leak
  238. Body io.ReadCloser
  239. JSON bool
  240. }
  241. // ImagePullOptions holds information to pull images.
  242. type ImagePullOptions struct {
  243. All bool
  244. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  245. PrivilegeFunc RequestPrivilegeFunc
  246. Platform string
  247. }
  248. // RequestPrivilegeFunc is a function interface that
  249. // clients can supply to retry operations after
  250. // getting an authorization error.
  251. // This function returns the registry authentication
  252. // header value in base 64 format, or an error
  253. // if the privilege request fails.
  254. type RequestPrivilegeFunc func() (string, error)
  255. // ImagePushOptions holds information to push images.
  256. type ImagePushOptions ImagePullOptions
  257. // ImageRemoveOptions holds parameters to remove images.
  258. type ImageRemoveOptions struct {
  259. Force bool
  260. PruneChildren bool
  261. }
  262. // ImageSearchOptions holds parameters to search images with.
  263. type ImageSearchOptions struct {
  264. RegistryAuth string
  265. PrivilegeFunc RequestPrivilegeFunc
  266. Filters filters.Args
  267. Limit int
  268. }
  269. // ResizeOptions holds parameters to resize a tty.
  270. // It can be used to resize container ttys and
  271. // exec process ttys too.
  272. type ResizeOptions struct {
  273. Height uint
  274. Width uint
  275. }
  276. // NodeListOptions holds parameters to list nodes with.
  277. type NodeListOptions struct {
  278. Filters filters.Args
  279. }
  280. // NodeRemoveOptions holds parameters to remove nodes with.
  281. type NodeRemoveOptions struct {
  282. Force bool
  283. }
  284. // ServiceCreateOptions contains the options to use when creating a service.
  285. type ServiceCreateOptions struct {
  286. // EncodedRegistryAuth is the encoded registry authorization credentials to
  287. // use when updating the service.
  288. //
  289. // This field follows the format of the X-Registry-Auth header.
  290. EncodedRegistryAuth string
  291. // QueryRegistry indicates whether the service update requires
  292. // contacting a registry. A registry may be contacted to retrieve
  293. // the image digest and manifest, which in turn can be used to update
  294. // platform or other information about the service.
  295. QueryRegistry bool
  296. }
  297. // ServiceCreateResponse contains the information returned to a client
  298. // on the creation of a new service.
  299. type ServiceCreateResponse struct {
  300. // ID is the ID of the created service.
  301. ID string
  302. // Warnings is a set of non-fatal warning messages to pass on to the user.
  303. Warnings []string `json:",omitempty"`
  304. }
  305. // Values for RegistryAuthFrom in ServiceUpdateOptions
  306. const (
  307. RegistryAuthFromSpec = "spec"
  308. RegistryAuthFromPreviousSpec = "previous-spec"
  309. )
  310. // ServiceUpdateOptions contains the options to be used for updating services.
  311. type ServiceUpdateOptions struct {
  312. // EncodedRegistryAuth is the encoded registry authorization credentials to
  313. // use when updating the service.
  314. //
  315. // This field follows the format of the X-Registry-Auth header.
  316. EncodedRegistryAuth string
  317. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  318. // into this field. While it does open API users up to racy writes, most
  319. // users may not need that level of consistency in practice.
  320. // RegistryAuthFrom specifies where to find the registry authorization
  321. // credentials if they are not given in EncodedRegistryAuth. Valid
  322. // values are "spec" and "previous-spec".
  323. RegistryAuthFrom string
  324. // Rollback indicates whether a server-side rollback should be
  325. // performed. When this is set, the provided spec will be ignored.
  326. // The valid values are "previous" and "none". An empty value is the
  327. // same as "none".
  328. Rollback string
  329. // QueryRegistry indicates whether the service update requires
  330. // contacting a registry. A registry may be contacted to retrieve
  331. // the image digest and manifest, which in turn can be used to update
  332. // platform or other information about the service.
  333. QueryRegistry bool
  334. }
  335. // ServiceListOptions holds parameters to list services with.
  336. type ServiceListOptions struct {
  337. Filters filters.Args
  338. // Status indicates whether the server should include the service task
  339. // count of running and desired tasks.
  340. Status bool
  341. }
  342. // ServiceInspectOptions holds parameters related to the "service inspect"
  343. // operation.
  344. type ServiceInspectOptions struct {
  345. InsertDefaults bool
  346. }
  347. // TaskListOptions holds parameters to list tasks with.
  348. type TaskListOptions struct {
  349. Filters filters.Args
  350. }
  351. // PluginRemoveOptions holds parameters to remove plugins.
  352. type PluginRemoveOptions struct {
  353. Force bool
  354. }
  355. // PluginEnableOptions holds parameters to enable plugins.
  356. type PluginEnableOptions struct {
  357. Timeout int
  358. }
  359. // PluginDisableOptions holds parameters to disable plugins.
  360. type PluginDisableOptions struct {
  361. Force bool
  362. }
  363. // PluginInstallOptions holds parameters to install a plugin.
  364. type PluginInstallOptions struct {
  365. Disabled bool
  366. AcceptAllPermissions bool
  367. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  368. RemoteRef string // RemoteRef is the plugin name on the registry
  369. PrivilegeFunc RequestPrivilegeFunc
  370. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  371. Args []string
  372. }
  373. // SwarmUnlockKeyResponse contains the response for Engine API:
  374. // GET /swarm/unlockkey
  375. type SwarmUnlockKeyResponse struct {
  376. // UnlockKey is the unlock key in ASCII-armored format.
  377. UnlockKey string
  378. }
  379. // PluginCreateOptions hold all options to plugin create.
  380. type PluginCreateOptions struct {
  381. RepoName string
  382. }