client.go 11 KB

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