client.go 9.3 KB

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