client.go 12 KB

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