client.go 12 KB

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