1package types // import "github.com/ory/dockertest/docker/types" 2 3import ( 4 "errors" 5 "fmt" 6 "io" 7 "os" 8 "strings" 9 "time" 10 11 "github.com/ory/dockertest/docker/types/container" 12 "github.com/ory/dockertest/docker/types/filters" 13 "github.com/ory/dockertest/docker/types/mount" 14 "github.com/ory/dockertest/docker/types/network" 15 "github.com/ory/dockertest/docker/types/registry" 16 "github.com/docker/go-connections/nat" 17) 18 19// RootFS returns Image's RootFS description including the layer IDs. 20type RootFS struct { 21 Type string 22 Layers []string `json:",omitempty"` 23 BaseLayer string `json:",omitempty"` 24} 25 26// ImageInspect contains response of Engine API: 27// GET "/images/{name:.*}/json" 28type ImageInspect struct { 29 ID string `json:"Id"` 30 RepoTags []string 31 RepoDigests []string 32 Parent string 33 Comment string 34 Created string 35 Container string 36 ContainerConfig *container.Config 37 DockerVersion string 38 Author string 39 Config *container.Config 40 Architecture string 41 Os string 42 OsVersion string `json:",omitempty"` 43 Size int64 44 VirtualSize int64 45 GraphDriver GraphDriverData 46 RootFS RootFS 47 Metadata ImageMetadata 48} 49 50// ImageMetadata contains engine-local data about the image 51type ImageMetadata struct { 52 LastTagTime time.Time `json:",omitempty"` 53} 54 55// Container contains response of Engine API: 56// GET "/containers/json" 57type Container struct { 58 ID string `json:"Id"` 59 Names []string 60 Image string 61 ImageID string 62 Command string 63 Created int64 64 Ports []Port 65 SizeRw int64 `json:",omitempty"` 66 SizeRootFs int64 `json:",omitempty"` 67 Labels map[string]string 68 State string 69 Status string 70 HostConfig struct { 71 NetworkMode string `json:",omitempty"` 72 } 73 NetworkSettings *SummaryNetworkSettings 74 Mounts []MountPoint 75} 76 77// CopyConfig contains request body of Engine API: 78// POST "/containers/"+containerID+"/copy" 79type CopyConfig struct { 80 Resource string 81} 82 83// ContainerPathStat is used to encode the header from 84// GET "/containers/{name:.*}/archive" 85// "Name" is the file or directory name. 86type ContainerPathStat struct { 87 Name string `json:"name"` 88 Size int64 `json:"size"` 89 Mode os.FileMode `json:"mode"` 90 Mtime time.Time `json:"mtime"` 91 LinkTarget string `json:"linkTarget"` 92} 93 94// ContainerStats contains response of Engine API: 95// GET "/stats" 96type ContainerStats struct { 97 Body io.ReadCloser `json:"body"` 98 OSType string `json:"ostype"` 99} 100 101// Ping contains response of Engine API: 102// GET "/_ping" 103type Ping struct { 104 APIVersion string 105 OSType string 106 Experimental bool 107} 108 109// ComponentVersion describes the version information for a specific component. 110type ComponentVersion struct { 111 Name string 112 Version string 113 Details map[string]string `json:",omitempty"` 114} 115 116// Version contains response of Engine API: 117// GET "/version" 118type Version struct { 119 Platform struct{ Name string } `json:",omitempty"` 120 Components []ComponentVersion `json:",omitempty"` 121 122 // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility 123 124 Version string 125 APIVersion string `json:"ApiVersion"` 126 MinAPIVersion string `json:"MinAPIVersion,omitempty"` 127 GitCommit string 128 GoVersion string 129 Os string 130 Arch string 131 KernelVersion string `json:",omitempty"` 132 Experimental bool `json:",omitempty"` 133 BuildTime string `json:",omitempty"` 134} 135 136// Commit holds the Git-commit (SHA1) that a binary was built from, as reported 137// in the version-string of external tools, such as containerd, or runC. 138type Commit struct { 139 ID string // ID is the actual commit ID of external tool. 140 Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time. 141} 142 143// Info contains response of Engine API: 144// GET "/info" 145type Info struct { 146 ID string 147 Containers int 148 ContainersRunning int 149 ContainersPaused int 150 ContainersStopped int 151 Images int 152 Driver string 153 DriverStatus [][2]string 154 SystemStatus [][2]string 155 Plugins PluginsInfo 156 MemoryLimit bool 157 SwapLimit bool 158 KernelMemory bool 159 CPUCfsPeriod bool `json:"CpuCfsPeriod"` 160 CPUCfsQuota bool `json:"CpuCfsQuota"` 161 CPUShares bool 162 CPUSet bool 163 IPv4Forwarding bool 164 BridgeNfIptables bool 165 BridgeNfIP6tables bool `json:"BridgeNfIp6tables"` 166 Debug bool 167 NFd int 168 OomKillDisable bool 169 NGoroutines int 170 SystemTime string 171 LoggingDriver string 172 CgroupDriver string 173 NEventsListener int 174 KernelVersion string 175 OperatingSystem string 176 OSType string 177 Architecture string 178 IndexServerAddress string 179 RegistryConfig *registry.ServiceConfig 180 NCPU int 181 MemTotal int64 182 //GenericResources []swarm.GenericResource 183 DockerRootDir string 184 HTTPProxy string `json:"HttpProxy"` 185 HTTPSProxy string `json:"HttpsProxy"` 186 NoProxy string 187 Name string 188 Labels []string 189 ExperimentalBuild bool 190 ServerVersion string 191 ClusterStore string 192 ClusterAdvertise string 193 Runtimes map[string]Runtime 194 DefaultRuntime string 195 //Swarm swarm.Info 196 // LiveRestoreEnabled determines whether containers should be kept 197 // running when the daemon is shutdown or upon daemon start if 198 // running containers are detected 199 LiveRestoreEnabled bool 200 Isolation container.Isolation 201 InitBinary string 202 ContainerdCommit Commit 203 RuncCommit Commit 204 InitCommit Commit 205 SecurityOptions []string 206} 207 208// KeyValue holds a key/value pair 209type KeyValue struct { 210 Key, Value string 211} 212 213// SecurityOpt contains the name and options of a security option 214type SecurityOpt struct { 215 Name string 216 Options []KeyValue 217} 218 219// DecodeSecurityOptions decodes a security options string slice to a type safe 220// SecurityOpt 221func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) { 222 so := []SecurityOpt{} 223 for _, opt := range opts { 224 // support output from a < 1.13 docker daemon 225 if !strings.Contains(opt, "=") { 226 so = append(so, SecurityOpt{Name: opt}) 227 continue 228 } 229 secopt := SecurityOpt{} 230 split := strings.Split(opt, ",") 231 for _, s := range split { 232 kv := strings.SplitN(s, "=", 2) 233 if len(kv) != 2 { 234 return nil, fmt.Errorf("invalid security option %q", s) 235 } 236 if kv[0] == "" || kv[1] == "" { 237 return nil, errors.New("invalid empty security option") 238 } 239 if kv[0] == "name" { 240 secopt.Name = kv[1] 241 continue 242 } 243 secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]}) 244 } 245 so = append(so, secopt) 246 } 247 return so, nil 248} 249 250// PluginsInfo is a temp struct holding Plugins name 251// registered with docker daemon. It is used by Info struct 252type PluginsInfo struct { 253 // List of Volume plugins registered 254 Volume []string 255 // List of Network plugins registered 256 Network []string 257 // List of Authorization plugins registered 258 Authorization []string 259 // List of Log plugins registered 260 Log []string 261} 262 263// ExecStartCheck is a temp struct used by execStart 264// Config fields is part of ExecConfig in runconfig package 265type ExecStartCheck struct { 266 // ExecStart will first check if it's detached 267 Detach bool 268 // Check if there's a tty 269 Tty bool 270} 271 272// HealthcheckResult stores information about a single run of a healthcheck probe 273type HealthcheckResult struct { 274 Start time.Time // Start is the time this check started 275 End time.Time // End is the time this check ended 276 ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe 277 Output string // Output from last check 278} 279 280// Health states 281const ( 282 NoHealthcheck = "none" // Indicates there is no healthcheck 283 Starting = "starting" // Starting indicates that the container is not yet ready 284 Healthy = "healthy" // Healthy indicates that the container is running correctly 285 Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem 286) 287 288// Health stores information about the container's healthcheck results 289type Health struct { 290 Status string // Status is one of Starting, Healthy or Unhealthy 291 FailingStreak int // FailingStreak is the number of consecutive failures 292 Log []*HealthcheckResult // Log contains the last few results (oldest first) 293} 294 295// ContainerState stores container's running state 296// it's part of ContainerJSONBase and will return by "inspect" command 297type ContainerState struct { 298 Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead" 299 Running bool 300 Paused bool 301 Restarting bool 302 OOMKilled bool 303 Dead bool 304 Pid int 305 ExitCode int 306 Error string 307 StartedAt string 308 FinishedAt string 309 Health *Health `json:",omitempty"` 310} 311 312// ContainerNode stores information about the node that a container 313// is running on. It's only available in Docker Swarm 314type ContainerNode struct { 315 ID string 316 IPAddress string `json:"IP"` 317 Addr string 318 Name string 319 Cpus int 320 Memory int64 321 Labels map[string]string 322} 323 324// ContainerJSONBase contains response of Engine API: 325// GET "/containers/{name:.*}/json" 326type ContainerJSONBase struct { 327 ID string `json:"Id"` 328 Created string 329 Path string 330 Args []string 331 State *ContainerState 332 Image string 333 ResolvConfPath string 334 HostnamePath string 335 HostsPath string 336 LogPath string 337 Node *ContainerNode `json:",omitempty"` 338 Name string 339 RestartCount int 340 Driver string 341 Platform string 342 MountLabel string 343 ProcessLabel string 344 AppArmorProfile string 345 ExecIDs []string 346 HostConfig *container.HostConfig 347 GraphDriver GraphDriverData 348 SizeRw *int64 `json:",omitempty"` 349 SizeRootFs *int64 `json:",omitempty"` 350} 351 352// ContainerJSON is newly used struct along with MountPoint 353type ContainerJSON struct { 354 *ContainerJSONBase 355 Mounts []MountPoint 356 Config *container.Config 357 NetworkSettings *NetworkSettings 358} 359 360// NetworkSettings exposes the network settings in the api 361type NetworkSettings struct { 362 NetworkSettingsBase 363 DefaultNetworkSettings 364 Networks map[string]*network.EndpointSettings 365} 366 367// SummaryNetworkSettings provides a summary of container's networks 368// in /containers/json 369type SummaryNetworkSettings struct { 370 Networks map[string]*network.EndpointSettings 371} 372 373// NetworkSettingsBase holds basic information about networks 374type NetworkSettingsBase struct { 375 Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`) 376 SandboxID string // SandboxID uniquely represents a container's network stack 377 HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface 378 LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix 379 LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address 380 Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port 381 SandboxKey string // SandboxKey identifies the sandbox 382 SecondaryIPAddresses []network.Address 383 SecondaryIPv6Addresses []network.Address 384} 385 386// DefaultNetworkSettings holds network information 387// during the 2 release deprecation period. 388// It will be removed in Docker 1.11. 389type DefaultNetworkSettings struct { 390 EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox 391 Gateway string // Gateway holds the gateway address for the network 392 GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address 393 GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address 394 IPAddress string // IPAddress holds the IPv4 address for the network 395 IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address 396 IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6 397 MacAddress string // MacAddress holds the MAC address for the network 398} 399 400// MountPoint represents a mount point configuration inside the container. 401// This is used for reporting the mountpoints in use by a container. 402type MountPoint struct { 403 Type mount.Type `json:",omitempty"` 404 Name string `json:",omitempty"` 405 Source string 406 Destination string 407 Driver string `json:",omitempty"` 408 Mode string 409 RW bool 410 Propagation mount.Propagation 411} 412 413// NetworkResource is the body of the "get network" http response message 414type NetworkResource struct { 415 Name string // Name is the requested name of the network 416 ID string `json:"Id"` // ID uniquely identifies a network on a single machine 417 Created time.Time // Created is the time the network created 418 Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level) 419 Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) 420 EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 421 IPAM network.IPAM // IPAM is the network's IP Address Management 422 Internal bool // Internal represents if the network is used internal only 423 Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. 424 Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. 425 ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. 426 ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. 427 Containers map[string]EndpointResource // Containers contains endpoints belonging to the network 428 Options map[string]string // Options holds the network specific options to use for when creating the network 429 Labels map[string]string // Labels holds metadata specific to the network being created 430 Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network 431 Services map[string]network.ServiceInfo `json:",omitempty"` 432} 433 434// EndpointResource contains network resources allocated and used for a container in a network 435type EndpointResource struct { 436 Name string 437 EndpointID string 438 MacAddress string 439 IPv4Address string 440 IPv6Address string 441} 442 443// NetworkCreate is the expected body of the "create network" http request message 444type NetworkCreate struct { 445 // Check for networks with duplicate names. 446 // Network is primarily keyed based on a random ID and not on the name. 447 // Network name is strictly a user-friendly alias to the network 448 // which is uniquely identified using ID. 449 // And there is no guaranteed way to check for duplicates. 450 // Option CheckDuplicate is there to provide a best effort checking of any networks 451 // which has the same name but it is not guaranteed to catch all name collisions. 452 CheckDuplicate bool 453 Driver string 454 Scope string 455 EnableIPv6 bool 456 IPAM *network.IPAM 457 Internal bool 458 Attachable bool 459 Ingress bool 460 ConfigOnly bool 461 ConfigFrom *network.ConfigReference 462 Options map[string]string 463 Labels map[string]string 464} 465 466// NetworkCreateRequest is the request message sent to the server for network create call. 467type NetworkCreateRequest struct { 468 NetworkCreate 469 Name string 470} 471 472// NetworkCreateResponse is the response message sent by the server for network create call 473type NetworkCreateResponse struct { 474 ID string `json:"Id"` 475 Warning string 476} 477 478// NetworkConnect represents the data to be used to connect a container to the network 479type NetworkConnect struct { 480 Container string 481 EndpointConfig *network.EndpointSettings `json:",omitempty"` 482} 483 484// NetworkDisconnect represents the data to be used to disconnect a container from the network 485type NetworkDisconnect struct { 486 Container string 487 Force bool 488} 489 490// NetworkInspectOptions holds parameters to inspect network 491type NetworkInspectOptions struct { 492 Scope string 493 Verbose bool 494} 495 496// Checkpoint represents the details of a checkpoint 497type Checkpoint struct { 498 Name string // Name is the name of the checkpoint 499} 500 501// Runtime describes an OCI runtime 502type Runtime struct { 503 Path string `json:"path"` 504 Args []string `json:"runtimeArgs,omitempty"` 505} 506 507// DiskUsage contains response of Engine API: 508// GET "/system/df" 509type DiskUsage struct { 510 LayersSize int64 511 Images []*ImageSummary 512 Containers []*Container 513 Volumes []*Volume 514 BuilderSize int64 515} 516 517// ContainersPruneReport contains the response for Engine API: 518// POST "/containers/prune" 519type ContainersPruneReport struct { 520 ContainersDeleted []string 521 SpaceReclaimed uint64 522} 523 524// VolumesPruneReport contains the response for Engine API: 525// POST "/volumes/prune" 526type VolumesPruneReport struct { 527 VolumesDeleted []string 528 SpaceReclaimed uint64 529} 530 531// ImagesPruneReport contains the response for Engine API: 532// POST "/images/prune" 533type ImagesPruneReport struct { 534 ImagesDeleted []ImageDeleteResponseItem 535 SpaceReclaimed uint64 536} 537 538// BuildCachePruneReport contains the response for Engine API: 539// POST "/build/prune" 540type BuildCachePruneReport struct { 541 SpaceReclaimed uint64 542} 543 544// NetworksPruneReport contains the response for Engine API: 545// POST "/networks/prune" 546type NetworksPruneReport struct { 547 NetworksDeleted []string 548} 549 550// SecretCreateResponse contains the information returned to a client 551// on the creation of a new secret. 552type SecretCreateResponse struct { 553 // ID is the id of the created secret. 554 ID string 555} 556 557// SecretListOptions holds parameters to list secrets 558type SecretListOptions struct { 559 Filters filters.Args 560} 561 562// ConfigCreateResponse contains the information returned to a client 563// on the creation of a new config. 564type ConfigCreateResponse struct { 565 // ID is the id of the created config. 566 ID string 567} 568 569// ConfigListOptions holds parameters to list configs 570type ConfigListOptions struct { 571 Filters filters.Args 572} 573 574// PushResult contains the tag, manifest digest, and manifest size from the 575// push. It's used to signal this information to the trust code in the client 576// so it can sign the manifest if necessary. 577type PushResult struct { 578 Tag string 579 Digest string 580 Size int 581} 582 583// BuildResult contains the image id of a successful build 584type BuildResult struct { 585 ID string 586} 587